Hi, I've the below Query
{
"query": {
"bool": {
"filter": [
{
"term": {
"is_deleted": 0
}
},
{
"term": {
"project.is_deleted": 0
}
},
{
"terms": {
"project.pid": [
1831
]
}
}
]
}
},
"size": 0,
"aggs": {
"aq_agg_test_case": {
"nested": {
"path": "test_case"
},
"aggs": {
"aq_agg_name": {
"terms": {
"field": "test_case.pid"
},
"aggs": {
"aq_agg_top_hits": {
"top_hits": {
"sort": [
{
"test_case.start_timestamp": "desc"
}
],
"size": 1
},
"aggs": {
"aq_agg_reverse_2": {
"reverse_nested": {},
"aggs": {
"aq_agg_app_env": {
"terms": {
"field": "app_environment.name"
}
}
}
}
}
}
}
}
}
}
}
}
Getting error response:
{
"error": {
"root_cause": [
{
"type": "aggregation_initialization_exception",
"reason": "Aggregator [aq_agg_top_hits] of type [top_hits] cannot accept sub-aggregations"
}
],
"type": "aggregation_initialization_exception",
"reason": "Aggregator [aq_agg_top_hits] of type [top_hits] cannot accept sub-aggregations"
},
"status": 500
}
The requirement is: Group the docs by ID's, then take the latest doc based on start_timestamp[Date field] in each group. Further aggregate those single docs based on "app_env" field.
Can you help me understanding how take on this problem