Bucket key/item counting

Hello,

I have a bucket that looks like this:

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : ###,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "group" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "2222",
          "doc_count" : 64,
          "types_count" : {
            "value" : 64
          }
        },
        {
          "key" : "3333",
          "doc_count" : 6,
          "types_count" : {
            "value" : 6
          }
        },
        {
          "key" : "4444",
          "doc_count" : 5,
          "types_count" : {
            "value" : 5
          }
        },
        {
          "key" : "5555",
          "doc_count" : 15,
          "types_count" : {
            "value" : 15
          }
        }
      ]
    }
  }
}

I am using metric aggregation to get this bucket.

"aggs": {
                "group": {
                    "terms": {
                            "field": "record1.keyword"      
                            },
                    "aggs": {
                        "types_count" : { "value_count" : { "field" : "record1.keyword" } }
                        } 
                    }
                }

I want to count the number of keys in the bucket.

example - Number of Record1 = 4
Is there a query or aggregation that does this?

It depends on what you are trying to do with this query. Is this part of a Kibana visualization? Is this something you're doing for an alert? One of the simpler ways to do this is using the count on the stats bucket pipeline agg, but it' s not support in Kibana UIs.

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