使用Elasticsearch计算文档数

编程入门 行业动态 更新时间:2024-10-17 02:57:16
本文介绍了使用Elasticsearch计算文档数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果要计算索引(Elasticsearch的索引)中的文档数,则(至少?)有两种可能性:

If one wants to count the number of documents in an index (of Elasticsearch) then there are (at least?) two possibilities:

  • 直接个计数

  • Direct count

POST my_index / _count

POST my_index/_count

应返回 my_index 中的文档数。

使用搜索

Using search

这里可以使用计数作为 search_type 或其他某种类型。在这两种情况下,都可以从字段 ['hits'] ['total']

Here one can use the count as the search_type or some other type. In either of the cases the total count can be extracted from the field ['hits']['total']

我的问题是:

  • 不同方法之间有什么区别?我应该选择哪一个?

  • what is the difference between the different approaches? Which one should I prefer?

我提出这个问题是因为根据所选择的方法,我遇到了不同的结果。我现在正在调试的问题,然后弹出该问题。

I raise this question because I'm experiencing different results depending on the chosen method. I'm now in the process of debugging the issue, and this question popped up.

推荐答案

可能 _count 有点快,因为它不必执行带有排名和结果获取的完整查询,并且只需返回大小即可。

Probably _count is a bit faster since it doesn't have to execute a full query with ranking and result fetching and can simply return the size.

了解更多有关如何获得不同结果的知识会很有趣。为此,我需要更多信息,例如您要发送的确切查询以及索引上是否有任何索引。

It would be interesting to know a bit more about how you manage to get different results though. For that I need more information like what exact queries you are sending and if any indexing is going on on the index.

但是假设您执行以下操作

But suppose that you do the following

  • 为某些文档编制索引
  • 刷新索引
  • _search 和 _count (全部匹配)将返回相同的总数。如果没有,那将是很奇怪。

    _search and _count (with a match all query) should return the same total. If not, that'd be very weird.

    更多推荐

    使用Elasticsearch计算文档数

    本文发布于:2023-11-30 09:22:43,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1649490.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:文档   Elasticsearch

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!