I am using Elasticsearch 7.11.1 and going to use top_metric aggregation to get the top records under the terms aggregation bucket. And my query is something like the following:
{
"size": 0,
"query": {
"bool": {
"must": [
{
"terms": {
"type": [
"data_type"
]
}
}
]
}
},
"aggregations": {
"field1": {
"terms": {
"field": "field1",
"size": 10
},
"aggregations": {
"field2": {
"terms": {
"field": "field2",
"size": 10
},
"aggregations": {
"field3": {
"terms": {
"field": "field3",
"size": 10
},
"aggregations": {
"amount": {
"extended_stats": {
"field": "amount"
}
},
"hits_here": {
"top_metrics": {
"metrics": [
{
"field": "field3"
},
{
"field": "field4"
},
{
"field": "field5"
}
],
"sort": "_score"
}
}
}
}
}
}
}
}
},
"track_total_hits": 2147483647
}
This query yields the expected results from ES, and now I would like to use this via JAVA API but I'm unable to find its related JAVA class in both ES 7.11 and 7.14, am I missing anything here or is it actually not available in API? If not available in API, is there any options to use the similar functionality?