【问题标题】:Elastic Search - aggregation group by index弹性搜索 - 按索引聚合分组
【发布时间】:2015-12-16 05:19:39
【问题描述】:

我有一些具有相同数据类型(相同字段)的索引。有没有办法在每个索引中获取某个字段的最大值(例如)?

假设我有以下数据:

index1.some_type:
    {"some_field": 23},
    {"some_field": 14},
    {"some_field": 43}

index2.some_type:
    {"some_field": 11},
    {"some_field": 65},
    {"some_field": 3}

我想为第一个索引获取最大值 43,为第二个索引获取最大值 65。 Elastic Search 允许在一个聚合查询中做这样的事情吗?

【问题讨论】:

    标签: elasticsearch lucene


    【解决方案1】:

    是的,绝对可以在terms aggregation 中使用特殊的_index meta field,然后在some_field 上使用max aggregation,如下所示:

    curl -XPOST localhost:9200/_search -d '{
      "size": 0,
      "aggs": {
        "byindex": {
          "terms": {
            "field": "_index",
            "size": 100
          },
          "aggs": {
            "max_value": {
              "max": {
                "field": "some_field"
              }
            }
          }
        }
      }
    }'
    

    【讨论】:

    • 酷,很高兴它有帮助!
    • 当有大量索引时,这不会返回所有索引。有没有办法强制 ES 查看所有索引并返回它们?
    • @LeninRajRajasekaran 我已经更新了我的答案(请参阅size 参数)
    猜你喜欢
    • 1970-01-01
    • 2017-06-19
    • 1970-01-01
    • 1970-01-01
    • 2019-11-08
    • 2021-02-19
    • 2023-03-18
    • 2021-10-11
    • 1970-01-01
    相关资源
    最近更新 更多