How to include group clause in count API of elasticsearch

前端 未结 1 1399
[愿得一人]
[愿得一人] 2021-01-27 23:29

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

相关标签:
1条回答
  • 2021-01-28 00:18

    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"
                  }
                }
              }
            ]
          }
        }
      }
    }
    

    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.

    0 讨论(0)
提交回复
热议问题