Hi All,
I need some help on below problem. Let me know how can I form my query to get expected output. Details posted in the stack overflow page. Thanks
Hi All,
I need some help on below problem. Let me know how can I form my query to get expected output. Details posted in the stack overflow page. Thanks
I got the solution I was looking for. This can be achieved by using reverse nested aggregation.
As per the reference(https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html),
When nested aggregation is applied, the query runs against the nested document. So to access any field of parent document inside nested doc, reverse nested aggregation can be used.
The final query looks like:
{
"size": 0,
"aggregations": {
"crankings": {
"nested": {
"path": "crankings"
},
"aggregations": {
"crankings": {
"terms": {
"field": "crankings.name.raw",
"size": 0
},
"aggregations": {
"internal_cardinality": {
"reverse_nested": { },
"aggregations": {
"cid": {
"cardinality": {
"field": "cid"
}
}
}
}
}
}
}
}
}
}
© 2020. All Rights Reserved - Elasticsearch
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.