Nest ignoring my percolate query property

岁酱吖の 提交于 2019-12-11 06:31:17

问题


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"
   }
 }
}

来源:https://stackoverflow.com/questions/45956630/nest-ignoring-my-percolate-query-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!