如何在Elasticsearch的计数API中包含组子句 [英] How to include group clause in count API of elasticsearch

查看:67
本文介绍了如何在Elasticsearch的计数API中包含组子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的应用程序,我使用的是Elasticsearch提供的count API,用于使用RestHighLevel Client获取Java中我的搜索查询的汇总值。但是,我面临这样一种情况,我需要根据需要包含按条件分组的货币来获取汇总。关于如何使用count API Java代码按条件添加分组的任何想法?

For my application I'm using count API provided by elasticsearch for getting the aggregate value for my search queries in Java using RestHighLevel Client. However I'm facing a situation where I need to get the aggregate based on the currency for which I need to include group by condition. Any idea on how to add group by condition using count API Java code?

推荐答案

以下是查询示例以获取计数

Following are the sample query to get the count using the aggregate function.

 {
  "size" : 0,
  "query" : {
    "term" : {
      "columnid" : {
        "value" : 1,
        "boost" : 1.0
      }
    }
  },
  "_source" : false,
  "stored_fields" : "_none_",
  "aggregations" : {
    "groupby" : {
      "composite" : {
        "size" : 10,
        "sources" : [
          {
            "14" : {
              "terms" : {
                "field" : "columnid",
                "missing_bucket" : true,
                "order" : "asc"
              }
            }
          }
        ]
      }
    }
  }
}




也可以将您的SQL查询转换为kibana qu使用以下查询查询-

Also use can translate your SQL query into kibana query using following query-



 POST _xpack/sql/translate
    {
       "query": "SELECT COUNT(*), columnid FROM Indexname WHERE columnid=1 group by columnid ",
       "fetch_size": 10
    }

如果可以解决您的问题,请标记答案。

Please mark answer if it resolves your problem.

这篇关于如何在Elasticsearch的计数API中包含组子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆