How to get total count in composite aggregation or any aggregation?

Hi,

I have documents with property tags{scope, tag} as nested document. I have used composite aggregation to find out unique tags available .

Composite aggregation does not return total number of buckets available.

I tried Scripted Metric aggregation to find out same, but it is taking almost 15 min.

{
"size": 0,
"aggregations": {
"tags_root": {
"nested": {
"path": "nested_tags"
},
"aggregations": {
"composite_scope_tag": {
"scripted_metric": {
"init_script": {"source":"state.transactions = ","lang":"painless"},
"map_script": {"source":"String tag_scope = doc['nested_tags.tag.keyword'].value + doc['nested_tags.scope.keyword'].value; if(!state.transactions.contains(tag_scope)){state.transactions.add(tag_scope)}","lang":"painless"},
"combine_script": {"source":"double count = 0; for (t in state.transactions) { count += 1 } return count","lang":"painless"},
"reduce_script": {"source":"double totalCount = 0; for (a in states) { totalCount += a } return totalCount","lang":"painless"}
}
}
}
}
}
}

How i can get total count of Unique tags available in documents?

Do any one have idea regarding " How to get total count in composite aggregation or any aggregation?" ?

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