Count results of top hits aggregation


(P) #1

Hi,
I am looking to do a count of the result of top hits aggregation.
The result of the top hits aggregation could be:
[
{
"defect_name": "defect1",
"status": "open"
},
{
"defect_name": "defect2",
"status": "open"
},
{
"defect_name": "defect3",
"status": "open"
}
]

And I want the query to return 3, the count of result set of the top hits aggregation. Is this possible in Elasticsearch

Thanks


(Jymit Singh Khondhu) #2

What do you need the top hits for?
Top hits gives you the hits, I suggest we would need to use a bucket here.

If you try this terms agg:

GET test/_search
{
    "aggs" : {
        "status_count" : {
            "terms" : { "field" : "status.keyword" }
        }
    }
}

resp:

"aggregations": {
    "status_count": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "open",
          "doc_count": 3

Does this suffice?

ref: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.