要在bool

时间:2016-02-02 05:19:38

标签: elasticsearch nest

我想编写将产生如下结果的查询。 Bool查询只需要一个boolQueryDescriptior。我想改用两个boolQueryDescriptors。

{
   "query": {
      "bool": {
         "must": [
            {
               "term": {
                  "id": "idValue"
               }
            }
         ],
         "should": [
            {
               "nested": {
                  "path": "nestedType",
                  "query": {
                     "match": {
                        "item2": "item2Value"
                     }
                  },
                  "inner_hits": {}
               }
            }
         ]
      }
   }
}

1 个答案:

答案 0 :(得分:3)

var results = client.Search<object>(sd => sd
    .Query(q => q
        .Bool(b => b
            .Must(m => m
                .Term("id", "idValue"))
            .Should(s => s
                .Nested(nq => nq
                    .Path("nestedType")
                    .Query(qd => qd
                        .Match(m => m
                            .OnField("item2")
                            .Query("item2Value")))
                    .InnerHits()))));
相关问题