Nest忽略我的percolate查询属性

时间:2017-08-30 09:23:17

标签: c# elasticsearch nest

我正在为具有percolate查询的类型建立索引,但Nest/elasticsearch选择忽略query属性。

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

编辑:2之间的某些属性名称巧合相同。它们在两个模型中的任何一个上完全表示不同的东西,并且可能以不同的方式映射。

我的映射:

对查询索引:

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)
                )
            )
        )
    ) 
 )

在doc index

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

索引我的查询模型:

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);

PercolatedQuery字段外,所有内容都已编入索引。在抓了很多头之后,我发现client甚至没有将它序列化。我运行以下内容只是为了看到PercolatedQuery未被序列化:

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

jsonString:

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

客户端看到的是渗透查询:

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

的queryString:

{
  "term": {
    "category": {
    "value": "some-valid-cat-on-my-doc-models"
   }
 }
}

0 个答案:

没有答案