【问题标题】:How to use multiple Composite Aggregations in ElasticSearch?如何在 ElasticSearch 中使用多个复合聚合?
【发布时间】:2021-08-25 19:09:33
【问题描述】:

我试图在 ElasticSearch 中获取两个composite aggregations,但第二个总是给我一个空桶。

GET /resolutions/_search

{
    "query": {
        "query_string": {
            "query": "*"
        }
    },
    "aggs": {
        "total": {
            "composite": {
                "sources": [
                    {"doi": {"terms": {"field": "doi"}}},
                    {"access_method": {"terms": {"field": "access_method"}}}
                ],
                "size": 10000
            }
        },
        "unqiue": {
            "composite": {
                "sources": [
                    {"doi": {"terms": {"field": "doi"}}},
                    {"access_method": {"terms": {"field": "access_method"}}},
                    {"session": {"terms": {"field": "session"}}}
                ],
                "size": 10000
            }
        }
    },
    "size": 0,
    "track_total_hits": false
}

在响应中,您可以看到存储桶中有 1000 个对象的第一个聚合 (total),但第二个聚合 (unique) 始终为空。我试过交换聚合的顺序,它总是第二个顺序是空的。

[![第二个桶空的响应][2]][2]

索引映射在:https://github.com/datacite/shiba-inu/blob/2d632d341a22a8dca2afec3b01c3b34030144c9c/templates/aggregating_es.json

为什么它返回一个空桶?

【问题讨论】:

  • 嘿 :) 我有同样的问题,当你有超过 2 个来源时,它似乎会发生。你能解决它吗?或证实我的想法?谢谢!最大

标签: elasticsearch elasticsearch-aggregation


【解决方案1】:

"after_key" 表示仍有结果。搜索返回了第一页。为了进一步分页,您需要重复相同的请求,并将"after" 设置为"after_key" 中的值。对每个新的 after_key 重复此操作,直到 after_key 丢失。

来自elastic的示例

GET /_search
{
  "size": 0,
  "aggs": {
    "my_buckets": {
      "composite": {
        "size": 2,
        "sources": [
          { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } },
          { "product": { "terms": { "field": "product", "order": "asc" } } }
        ],
        "after": { "date": 1494288000000, "product": "mad max" } 
      }
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 2020-07-21
    • 2023-03-06
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多