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
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.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.