2

I'm indexing a type that has percolate query but Nest/elasticsearch choose to ignore the query property.

public class MyQueryModel
{
  public string Id { get; set; }
  public string UserId { get; set;}
  public string Email { get ; set;}
  public string Name { get; set; }
  public string State { get; set; }
  public QueryContainer PercolatedQuery { get; set; }
}

public class DocModel
{
   public string Id { get; set; }
   public string Title { get; set; }
   public string State { get; set; }
   public string Category { get; set;}
   public string Email { get; set; }
}

EDIT: some of property names between the 2 are same by coincidence. They totally mean different things on either of the 2 models and maybe mapped differently.

my mappings:

on queries index:

client.CreateIndex("on_my_queries", c => c
    .Mappings(m => m
        .Map<MyQueryModel>(mq => mq
            .AutoMap()
            .Properties(props => props
                .Percolator(perc => perc
                    .Name(m => m.PercolatedQuery)
                )
            )
        )
    ) 
 )

on doc index

client.CreateIndex("on_my_docs", c => c
    .Mappings(m => m
        .Map<MyDocModel>(md => md
            .AutoMap()
        )
    ) 
 ) 

Indexing my query model:

var queryModel = new MyQueryModel
{
  Id = "some-id",
  UserId = "some-user-id",
  Email = "some-valid-email",
  State = "some-valid-state",
  PercolatedQuery = new TermQuery
  {
     Field = "category",
     Value = "some-valid-cat-on-my-doc-models"
  }
}

var request = new IndexRequest<QueryModel>(DocumentPath<MyQueryModel>.Id(queryModel));

var result = client.Index(request);

Everything gets indexed except the PercolatedQuery field. After scratching a lot of my head, I find out that client is not even serializing it. I ran the following only to see that PercolatedQuery was not serialized:

var jsonString = client.Serializer.SerializeToString(request);

jsonString:

{
  "id" : "some-id",
  "userId" : "some-user-id",
  "email: : "some-valid-email",
  "state" : "some-valid-state"
}

What client see as percolated query:

var queryString = client.Serializer.SerializeToString(queryModel.PercolatedQuery);

queryString:

{
  "term": {
    "category": {
    "value": "some-valid-cat-on-my-doc-models"
   }
 }
}
rethabile
  • 3,029
  • 6
  • 34
  • 68
  • Take a look at the docs and tests for Percolation as they'll help you: https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/percolate-query-usage.html and https://github.com/elastic/elasticsearch-net/blob/626835383fbeec5523da59bd2aa09cfb4a0a4dc5/src/Tests/QueryDsl/Specialized/Percolate/PercolateQueryUsageTests.cs – Russ Cam Aug 30 '17 at 10:47
  • They are not helping. The docs is where i started and it says nothing about the mappings and indexing the query document. As for the github, trying to map more than 1 type throws an [exception](https://stackoverflow.com/questions/45953606/creating-an-index-for-percolate-query). – rethabile Aug 30 '17 at 12:00
  • What version of Elasticsearch are you running against? And what version of NEST are you using? – Russ Cam Aug 30 '17 at 22:50
  • `ES 6.0.0-alpha1` and `NEST 6.0.0-alpha1`. Holy me! I labeled the property with `[JsonIgnore]` for my api endpoint, unaware that `NEST` will ingore it as well. – rethabile Aug 31 '17 at 11:20
  • There's a change coming in 6.0 where multiple types in one index is no longer allowed: https://www.elastic.co/blog/index-type-parent-child-join-now-future-in-elasticsearch. I'd recommend using latest stable releases of both Elasticsearch and NEST for the moment – Russ Cam Aug 31 '17 at 11:27
  • But mapping 2 types still throws an exception. Does that mean I have to combine my `MyQueryModel` and `DocModel` into 1 `POCO` as is being suggested [here](https://www.elastic.co/guide/en/elasticsearch/reference/6.x/query-dsl-percolate-query.html) – rethabile Aug 31 '17 at 11:28
  • Mapping two types in one index in 5.x is fine, but you may get an exception if you try to map the _same_ named properties on two different types in the same index in different ways (this is one of the reasons for the change coming in 6.0). – Russ Cam Aug 31 '17 at 11:35

0 Answers0