Count buckets of aggregation

Hi !

I'am getting it as response after bucket_selector:

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 10,
        "successful": 10,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 4,
        "max_score": 0,
        "hits": []
    },
    "aggregations": {
        "groupby_id": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": "SQ1dioA8pOktHQdyz",
                    "doc_count": 1,
                    "is_confirmation_filter": {
                        "doc_count": 1
                    }
                },
                {
                    "key": "uuyjhiHQdyz1",
                    "doc_count": 1,
                    "is_confirmation_filter": {
                        "doc_count": 1
                    }
                }
            ]
        }
    }

So, how can i get the count of "buckets" result of aggregation and bucket_selector ?
In this case, count equals 2.
Sorry about anything... starting to learn about elastic use today.

This is my query:

/elasticsearch/confirmations,blocks/_search?

{
   "size":0,
   "query":{
      "bool":{
         "should":[
            {
               "bool":{
                  "must":[
                     {
                        "term":{
                           "pK":"hRFFE9g0wThY1Z"
                        }
                     },
                     {
                        "term":{
                           "date":1549677600000
                        }
                     }
                  ]
               }
            },
            {
               "bool":{
                  "must":[
                     {
                        "term":{
                           "mK":"SQ1dioA8pOktHQdyz"
                        }
                     },
                     {
                        "bool":{
                           "must_not":{
                              "exists":{
                                 "field":"pK"
                              }
                           }
                        }
                     }
                  ]
               }
            }
         ]
      }
   },
   "aggs":{
      "groupby_id":{
         "terms":{
            "field":"u",
            "size":25,
            "order":{
               "_count":"asc"
            }
         },
         "aggs":{
            "is_confirmation_filter":{
               "filter":{
                  "bool":{
                     "filter":[
                        {
                           "exists":{
                              "field":"pK"
                           }
                        }
                     ]
                  }
               }
            },
            "average_distinct":{
               "bucket_selector":{
                  "buckets_path":{
                     "group_by_count":"_count",
                     "is_confirmation":"is_confirmation_filter._count"
                  },
                  "script":"params.is_confirmation > 0 && params.group_by_count <2"
               }
            }
         }
      }
   }
}

There's also a _bucket_count property which you can use: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html#_special_paths

Thx!

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