ElasticSearch count 返回结果

标签 elasticsearch

我想计算由于具有大小限制的查询而返回的文档数。例如,我运行以下查询:

curl -XGET http://localhost:9200/logs_-*/a_logs/_search?pretty=true -d '
{
"query" : {
    "match_all" : {  }
},
"size" : 5,
"from" : 8318
}'

我得到:

{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 159,
"successful" : 159,
"failed" : 0
},
  "hits" : {
  "total" : 8319,
  "max_score" : 1.0,
  "hits" : [ {
....

与我的查询匹配的文档总数是 8319,但我最多提取了 5 个。自从我“从”8318 查询以来,只返回了 1 个文档。

在响应中,我不知道返回了多少文件。我想编写一个查询,以便返回的文档数量也出现在某些字段中。也许某些方面可能会有所帮助,但我无法弄清楚。请帮忙。

最佳答案

您的查询:

{
"query" : {
    "match_all" : {  }
},

=> 意味着你询问你所有的数据

“尺寸”:5,

=> 你只想显示 5 个结果

“来自”:8318

=> 你从8318条记录开始

ElasticSearch 响应:

....

"hits" : {
  "total" : 8319,

... => Elasticsearch 告诉你他的索引中有 8319 个结果。

你问他所有的结果,你从8318开始。

8319 - 8318 = 1 所以你有 1 个结果。

尝试删除 from。

关于ElasticSearch count 返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16564960/

相关文章:

java - 如何在 Elasticsearch Java 高级客户端 6.8 的响应中只获取失败的文档

java - 如何从 Avg Aggregation Builder elasticsearch 获取特定键的平均值

elasticsearch - 在Kibana中将Filebeat消息字段拆分为多个字段

types - 按类型限制 ElasticSearch 聚合?

elasticsearch - 在Elastic Search中进行聚合之前,是否可以在任何函数上应用修整方法

Elasticsearch 集群 - 没有已知的主节点,安排重试

python - 使用 "django-elasticsearch-dsl"将 ElasticSearch 连接到 Django 导致在尝试创建/重建索引时出现 ConnectionError

elasticsearch - 有没有办法检查当前批量队列大小 Opensearch?

elasticsearch - 如何在ES 7.3v中检查ES文档的创建时间?

Elasticsearch 跨多个索引的单个分析器