Composite aggregation buckets total count

hi,

how to count buckets total, when i have the following ES query

"size": 0,
"aggs": {
    "buckets": {
        "composite": {
            "size": 20,
            "sources": [
                {"age": {"terms": {"field": "age"}}},
                {"weight": {"terms": {"field": "weight"}}},
            ]
        },
        "aggs": {
            "Max Wheight": {
                "max": {
                    "field": "weight"
                }
            },
        }
    },
}

or such as

{
	"query": {
	    "query_string": {
	        "query": "age:>=24"
	    }
	},
	"size": 0,
	"aggs": {
	    "group_by_pni": {
	        "terms": {
	            "field": "pni"
	        },
	        "aggs": {
	            "group_by_code": {
	                "terms": {
	                    "field": "code.keyword"
	                },
	                "aggs": {
	                    "group_by_age": {
	                        "terms": {
	                            "field": "age"
	                        },
	                        "aggs": {
	                            "counts age": {
	                                "value_count": {
	                                    "field": "age"
	                                }
	                            },
	                            "max_age": {
	                                "max": {
	                                    "field": "age"
	                                }
	                            }
	                        }
	                    }
	                }
	            }
	        }
	    },
	}
}

can you help me? thanks in advance

1 Like

I don't believe there's a way to get the total bucket count, because the composite agg doesn't know how many buckets there are until it has paged through them all.

I think the best you can do is keep a running counter client-side and increment it with each page that you receive.

That's the trade-off that composite pays; memory-friendly, streaming collection of results at the expense of multiple round-trips and not knowing the buckets up-front.

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