弹性搜索:JSON到NEST查询没有重复

时间:2016-10-14 17:56:11

标签: c# elasticsearch nest

如何将json查询转换为下面的嵌套查询并删除重复项?

{
      "size": 30,
      "query": {
          "multi_match": {
            "query": "london",
            "operator": "OR",
            "fields": [
            "name",
             "venueTown"
            ]
          }
  }
}

1 个答案:

答案 0 :(得分:2)

您可以稍微简化聚合部分,并将最热门的匹配放在

var searchResult = client.Search<SearchResult>(request => request
    // Your existing query below...
    //.Query(q => q)
    .Size(0)
    .Aggregations(a => a
        // simplify the terms aggregation
        .Terms("query", tr => tr
            .Field("name")
            .Size(30)
        )
        // Add the top hits aggregation
        .TopHits("top", th => th
            .Size(1)
        )
    )
);
相关问题