elasticsearch 只返回总命中数

art*_*170 4 elasticsearch kibana

我想向仅返回总命中数的 ELS 发送查询。

没有别的

就像我得到回应一样

{   "took": 1111,   "timed_out": false,   "_shards": {
    "total": 9,
    "successful": 9,
    "failed": 0   },   "hits": {
    "total": 731552,   
 }
Run Code Online (Sandbox Code Playgroud)

我只想打印 731552

现在我只是发送:

curl http://server:9200/games_profiler/_search

谢谢

Val*_*Val 7

您可以为此使用响应过滤

curl http://server:9200/games_profilder/_search?filter_path=hits.total
Run Code Online (Sandbox Code Playgroud)

这将产生

{
  "hits": {
    "total": 731552
  }
}
Run Code Online (Sandbox Code Playgroud)

如果你真的只想得到总数,你可以jq像这样管道结果:

curl http://server:9200/games_profilder/_search?filter_path=hits.total | jq '.hits.total'
Run Code Online (Sandbox Code Playgroud)

这只会产生数字 731552