【发布时间】:2017-05-15 17:30:28
【问题描述】:
我是弹性搜索聚合的新手。
我正在寻找一种将自定义字段添加到聚合的每个存储桶的方法,该字段应该是一个数组或字符串,每个特定项目之间都有一些分隔符。
我有弹性搜索映射映射
{
"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 个文档。 我的目标是每个存储桶都有一个额外的字段,其中包含每个文档_id,最好是数组,例如“refs”:[1, 2, 3, 4, ...]
【问题讨论】:
标签: arrays elasticsearch aggregate