elasticsearch,aggregate,Arrays,elasticsearch,Aggregate" /> elasticsearch,aggregate,Arrays,elasticsearch,Aggregate" />

Arrays ElasticSearch聚合将额外字段作为数组添加到存储桶

Arrays ElasticSearch聚合将额外字段作为数组添加到存储桶,arrays,elasticsearch,aggregate,Arrays,elasticsearch,Aggregate,我对弹性搜索的聚合非常陌生 我正在寻找一种将自定义字段添加到聚合的每个bucket的方法,该字段应该是一个数组或字符串,每个特定项之间都有分隔符 我有弹性搜索映射 { "mappings": { "place": { "properties": { "name": { "type": "string", } }

我对弹性搜索的聚合非常陌生

我正在寻找一种将自定义字段添加到聚合的每个bucket的方法,该字段应该是一个数组或字符串,每个特定项之间都有分隔符

我有弹性搜索映射

{
    "mappings": {
        "place": {
            "properties": {
                "name": {
                    "type": "string",
                }
            }
        }
    }
}
我有一个聚合查询

  {
  size: 0,
  query: {...},
  aggs: {
    "merchants": {
      "terms": {
        "field": "name",
        "min_doc_count": 1,
        "order": {
          "max_score": "desc"
        }
      },
      "aggs": {
        "max_score": {
          "max": {
            "script": "_score"
          }
        }
      }
    }
  }
}
我有这样的结果:

{
    "took": 2,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 82,
        "max_score": 0,
        "hits": []
    },
    "aggregations": {
        "merchants": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": "Post Office",
                    "doc_count": 82,
                    "max_score": {
                        "value": 1.7627471685409546
                    }
                }
            ]
        }
    }
}
在本例中,此结果包含82个文档。
我的目标是,每个bucket都有一个额外的字段,其中包含每个文档id,最好是数组,例如“refs”:[1,2,3,4,…]

实现这一点的最佳方法是在
\u id
字段上添加另一个
术语
子聚合:

{
  size: 0,
  query: {...},
  aggs: {
    "merchants": {
      "terms": {
        "field": "name",
        "min_doc_count": 1,
        "order": {
          "max_score": "desc"
        }
      },
      "aggs": {
        "ids": {               <--- add this
          "terms": {
            "field": "_id",
            "size": 100
          }
        },
        "max_score": {
          "max": {
            "script": "_score"
          }
        }
      }
    }
  }
}
{
尺寸:0,
查询:{…},
aggs:{
“商人”:{
“条款”:{
“字段”:“名称”,
“最小单据数”:1,
“命令”:{
“最大分数”:“描述”
}
},
“aggs”:{

“ids”:{我可以省略“size”:100吗?因为我不知道确切的值,应该在那里。您可以设置任意高的值,但默认情况下只返回10个术语。