Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hi Author of NEST here,</p> <p>If you use the annotations you need to manually call</p> <pre class="lang-cs prettyprint-override"><code>var createIndex = client.CreateIndex("default_index", new IndexSettings { }); client.Map&lt;Movie&gt;(); </code></pre> <p>Before the first call to index. <code>Nest</code> wont apply the mapping on each index call since that would incur too much of overhead. Older versions of elasticsearch would just create the index if it doesn't exist and would not need the <code>CreateIndex</code> call.</p> <p>Since you want to facet on a nested type you have to pass <code>.Nested("genres")</code> to the facet call. </p> <p>The numbers you saw were actually the nested docids :)</p> <p>Here's my modified program.cs that works:</p> <pre class="lang-cs prettyprint-override"><code>using System; using System.Collections.Generic; using System.Linq; using Nest; namespace Demo { class Program { public class Movie { public int Id { get; set; } public string Title { get; set; } public string Description { get; set; } [ElasticProperty(Type=FieldType.nested)] public List&lt;Genre&gt; Genres { get; set; } public int Year { get; set; } } public class Genre { // public int Id { get; set; } [ElasticProperty(Index = FieldIndexOption.not_analyzed)] public string GenreTitle { get; set; } } static void Main(string[] args) { var setting = new ConnectionSettings("localhost", 9200); setting.SetDefaultIndex("default_index"); var client = new ElasticClient(setting); // delete previous index with documents client.DeleteIndex&lt;Movie&gt;(); var createIndexResult = client.CreateIndex("default_index", new IndexSettings { }); var mapResult = client.Map&lt;Movie&gt;(); // put documents to the index var genres = new List&lt;Genre&gt;(); for (var i = 0; i &lt; 100; i++) genres.Add(new Genre { GenreTitle = string.Format("Genre {0}", i) }); for (var i = 0; i &lt; 1000; i++) { client.Index(new Movie { Id = i, Description = string.Format("Some movie description {0}", i), Title = string.Format("Movie Title {0}", i), Year = 1980 + (i % 10), Genres = genres.OrderBy(x =&gt; Guid.NewGuid()).Take(10).ToList() }); } // query with facet on nested field property genres.genreTitle var queryResults = client.Search&lt;Movie&gt;(x =&gt; x .From(0) .Size(10) .MatchAll() .FacetTerm(t =&gt; t .OnField(f =&gt; f.Year) .Size(30)) .FacetTerm(t =&gt; t .Size(5) .OnField(f =&gt; f.Genres.Select(f1 =&gt; f1.GenreTitle)) .Nested("genres") ) ); var yearFacetItems = queryResults.FacetItems&lt;FacetItem&gt;(p =&gt; p.Year); foreach (var item in yearFacetItems) { var termItem = item as TermItem; Console.WriteLine(string.Format("{0} ({1})", termItem.Term, termItem.Count)); } var genresFacetItems = queryResults.FacetItems&lt;FacetItem&gt;(p =&gt; p.Genres.Select(f =&gt; f.GenreTitle)); foreach (var item in genresFacetItems) { var termItem = item as TermItem; Console.WriteLine(string.Format("{0} ({1})", termItem.Term, termItem.Count)); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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