我是ElasticSearch的新手我想要基于id的计数文档,但我想在id中传递数组,如“myId”:[1,2,3,4,5]
我希望计数的每个id
当前输入
GET /probedb_v1/probe/_count
{
"query": {
"match_phrase": {
"myId": 1
}
}
}
当前输出
{ "count": 6929,
"_shards":{ "total": 1,
"successful": 1,
"failed": 0
}
}
我的输入是什么 要求的输出
{ "count": [6929,5222,65241,5241,6521],
"_shards":{ "total": 1,
"successful": 1,
"failed": 0
}
}
还需要elasticsearch java-api的代码
答案 0 :(得分:1)
你可以这样做:
GET /probedb_v1/probe/_search
{
"size": 0,
"query": {
"terms": {
"myId": [123, 44]
}
},
"aggs": {
"NAME": {
"terms": {
"field": "myId",
"size": 50
}
}
}
}
这将为您提供此输出:
"aggregations": {
"NAME": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 123,
"doc_count": 3
},
{
"key": 44,
"doc_count": 2
}
]
}
}