0

我是 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的代码

4

1 回答 1

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
            }
         ]
      }
   }
于 2016-05-18T12:18:06.847 回答