Term aggregations from union of nested list

Hi All,

I would like to do a simple count aggregation from a distinct list of my union of two nested list. But I have no idea, how can i do this.
This is my sample structure:
"_source": {
"productId": 1,
"materialMain": [
"name": "Wood",
"id": 15
"name": "Oak",
"id": 151
"materialSecondary": [
"name": "Wood",
"id": 15
"name": "Spruce",
"id": 152

The accepted result should be:
Wood, Id:15, count = 1
Oak, Id:151, count = 1
Spruce, Id: 152, count = 1

Thank you for your help in advance!

All the terms live in one doc.
The terms aggregation returns the term values eg "Wood" and a doc_count. The doc_count is the number of docs that contain a term, not the total number of times the term is mentioned in the docs.

The only complication I see is that you're getting the terms from >1 field, in which case you'd need to use a script to merge the sets of values from the 2 fields before returning them to the terms aggregation.

Okey, I am going to try script to merge arrays.

Thank you for your answer

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