简体   繁体   English

如何在索引elasticsearch java中查找类型中所有记录的计数

[英]How to find count of all records in type inside index elasticsearch java

I have started working recently working on elasticsearch in Java platform. 我最近开始在Java平台上研究elasticsearch I wanted to find out count of all documents inside type in specific index with help of Java without fetching all records. 我希望借助Java在没有获取所有记录的情况下找出特定索引中类型内所有文档的数量。 Found following ways to do this not sure which will be better choice. 找到以下方法来做到这一点不确定哪个是更好的选择。

  • CountRequestBuilder (Deprecated in recent releases) CountRequestBuilder (在最近的版本中已弃用)
  • prepareSearch with setsize set to 0. prepareSearch用setsize设置为0。
  • Using SearchType.COUNT while creating search. 在创建搜索时使用SearchType.COUNT

    Little confused with above options. 与上述选项有点混淆。 is there any better solution ? 还有更好的解决方案吗? Thanks in advance. 提前致谢。

You are looking for a simple aggregation over the field _type . 您正在寻找字段_type上的简单聚合。 Here is a JSON equivalent: 这是一个等效的JSON:

{   
"aggs": {
    "my_terms": {
       "terms": {
         "field": "_type"
       }
     }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM