如何在多索引搜索中按索引获取聚合聚合?

how to get aggregate aggregations by indices in a multiple index search?

我有一个适用于单个索引的聚合查询,聚合看起来像:

"aggs":{  
    "my_buckets":{  
      "composite":{  
        "size":1000,
        "sources":[  
          {  
            "checksumField":{  
              "terms":{  
               "field":"checkSum.keyword"
              }
            }
          }
        ]
      },
      "aggs":{  
        "catagories":{  
          "top_hits":{  
            "sort":[  
              {  
                "createdDate":{  
                  "order":"desc"
                 }
              }
            ],
            "size":1,
            "_source":[  
             "some_field"
            ]
          }
        }
      }
    }
  }

这适用于单个索引,但是当我在 GET uri 中包含多个索引作为逗号分隔值时,如果第一个索引本身有很多条目(比如 1000),我无法看到结果其他索引作为我的聚合结果的最大大小设置为 1000,但是我需要的是所有索引的热门点击(如果有两个索引,则说每个索引的前 500 个),我如何修改 aggs 主体以获得那种聚合结果

sources数组中,可以在_index字段上添加一个terms聚合:

    "sources":[  
      {  
        "index":{  
          "terms":{  
           "field":"_index"
          }
        }
      },       
      {  
        "checksumField":{  
          "terms":{  
           "field":"checkSum.keyword"
          }
        }
      }
    ]

问题解决了,下面是returns composite buckets by indices

的aggs部分
GET index1,index2,index3/type/_search

 "aggs": {
    "my_buckets": {
      "composite": {
        "size": 3,
        "sources": [
          {
            "indexAgg": {
              "terms": {
                "field": "_index"
              }
            }
          }
        ]
      },
      "aggs": {
        "checksumField": {
          "terms": {
            "field": "checkSum.keyword",
            "size":2
          },
          "aggs": {
            "catagories": {
              "top_hits": {
                "sort": [
                  {
                    "createdDate": {
                      "order": "desc"
                    }
                  }
                ],
                "size": 1,
                "_source": [
                  "some_field"
                ]
              }
            }
          }
        }
      }
    }
  }

生成的聚合产生三个主桶(用于三个模板)和每个 2(这是我需要根据提供的模板数量计算的大小,通过均匀除以 1000)基于校验和字段的聚合,由问题中的原始查询返回。因此,通过这些更改,我可以获得每个索引的固定命中数。