我想在列表1中获取每个放入数组的“adminId”文档。
这不是用户索引,因此我为每个用户提供了多个文档。
这是我尝试但我得到多个文件与相同的adminId有些缺失:
{
size: 10,
query: {
bool: {
must: [
{
terms: {
adminId: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
}
}
]
}
}
}
如何告诉ES“为我给你的每个值取一个至少1个文件”?
How to get (any) one document per given bucket?
使用top hits aggregatn作为OP建议。
curl -H 'Content-Type: application/json' localhost:9200/myindex/_search?pretty -d '
{
"size": 0,
"query": {
"bool": {
"must": {
"terms": {
"adminId": ["CA", "NY", "TX"]
}
}
}
},
"aggs": {
"aggregation_name_1": {
"terms": {
"size": 10000,
"field": "adminId"
},
"aggs": {
"aggregation_name_2": {
"top_hits": {
"size": 1
}
}
}
}
}
}
'
注意
"size": 10000
意味着我们想要10000
桶的数据(不同的adminId
值)。如果您有更多桶,请调整此值。"size": 1
表示每个桶,返回(任何)一个文档。