Note that there are some explanatory texts on larger screens.

plurals
  1. POusing NEST with Elastic Search for collections
    text
    copied!<p>I'm trying to get my hands dirty with Elastic Search via the NEST .Net api and running into a couple of problems. I suspect I've misunderstood something, or am modelling my docs incorrectly but would appreciate some help. </p> <p>I have a document with collections in it. A similar trite example below : </p> <pre class="lang-cs prettyprint-override"><code>public class Company { public DateTime RegisteredOn {get;set;} public string Name {get;set;} [ElasticProperty(Type = FieldType.nested)] public List&lt;Employee&gt; Employees {get;set;} } public class Employee { public string FirstName {get;set;} public string LastName {get;set;} [ElasticProperty(Type = FieldType.nested)] public List&lt;SalesFigure&gt; SalesFigures {get;set} } public class SaleFigure { public int AverageMonthlySaleValue {get;set;} public int AverageVolumeSold {get;set;} } </code></pre> <p>I've created an index with some data in at each level of the hierarchy and before indexing have called <code>client.MapFromAttributes&lt;Company&gt;();</code> </p> <p>The following works, but I'd like to understand how I'd find all companies with employees with a firstName of Bob, and or find all companies with employees who have a an average AverageMonthlySaleValue > $1100</p> <pre class="lang-cs prettyprint-override"><code>client.Search&lt;Company&gt;(query =&gt; query.Index("companies").Type("company") .From(0) .Size(100) .Filter(x =&gt; x.Term(n =&gt; n.Name, "Microsoft"))); </code></pre> <p>Nested queries/filters have been suggested as has suggestions that I ought to flatten my document which I can do, but I'm trying to create a model which better represents the real domain so am in a quandary. </p> <p>Equally, I know that I'll also have to use facets at some point so want to structure everything correctly to support that. </p> <p>Thanks Tim</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload