【问题标题】:To find the distinct fields in an elastic search query在弹性搜索查询中查找不同的字段
【发布时间】:2016-12-28 11:40:53
【问题描述】:

我只需要一个字段的值,并且其中有重复的值。

POST _search
{
    "query": {
        "bool": {
            "must": [
               {"term": {
           "report": {
              "value": "some_value"
           }
        }}
            ]
        }
    },
    "fields": [
            "field_name"
    ]
}

我只需要 field_name 的不同值。

【问题讨论】:

    标签: elasticsearch field


    【解决方案1】:

    如果您有查询,使用 terms 聚合然后应用 top_hits 聚合以缩小到您想要实现的单个值:

    "aggs": {
        "values": {
          "terms": {
            "field": "your_field"
          }
        }
      }
    

    这个SO 也很有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 2016-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-28
      相关资源
      最近更新 更多