【问题标题】:elasticsearch return total hits onlyelasticsearch 仅返回总点击次数
【发布时间】:2017-05-03 19:37:18
【问题描述】:

我想向 ELS 发送只返回总点击数的查询。

没有别的

如果我得到了回应

{   "took": 1111,   "timed_out": false,   "_shards": {
    "total": 9,
    "successful": 9,
    "failed": 0   },   "hits": {
    "total": 731552,   
 }

我只想打印 731552

现在我只是发送:

卷曲http://server:9200/games_profilder/_search

谢谢

【问题讨论】:

  • 嗨,当我尝试执行此操作时,我的点击次数限制为 10,000。我不需要一次匹配我的查询的所有文档,但我确实需要知道匹配的总数,而不仅仅是超过 10,000 个。我该如何解决这个问题?
  • @Dude 使用/_count 端点而不是/_search

标签: elasticsearch kibana


【解决方案1】:

您可以为此使用response filtering

curl http://server:9200/games_profilder/_search?filter_path=hits.total

这将产生

{
  "hits": {
    "total": 731552
  }
}

如果你真的只想得到总数,你可以像这样使用jq 传递结果:

curl http://server:9200/games_profilder/_search?filter_path=hits.total | jq '.hits.total'

这将只产生数字731552

【讨论】:

  • 这是一个直接在 shell 内部的与语言无关的解决方案。如果您使用 python,则只需引用结果对象的 ['hits']['total'] 属性。
  • 这看起来非常适合减少有效负载大小。为了整体效率(假设您需要大量运行此类查询),进行源过滤是否有意义?我猜响应过滤器是在最后应用的,也许 ES 将大量数据拉入内存只是为了在发送响应之前丢弃它。但这只是猜测。
  • @ToddMenier 源过滤确实有帮助。
猜你喜欢
  • 2014-02-17
  • 1970-01-01
  • 1970-01-01
  • 2013-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多