Разложить вложенную агрегацию в Opensearch
Есть запрос с вложенной агрегацией:
{
"size": 0,
"query": {
"bool": {
"filter": [
{
"range": {
"@timestamp": {
"from": "now-20m",
"to": null
}
}
}
]
}
},
"aggregations": {
"composite_agg": {
"terms": {
"field": "composite.keyword"
},
"aggregations": {
"interface": {
"terms": {
"field": "interface.keyword"
},
"aggregations": {
"out_error": {
"date_histogram": {
"field": "@timestamp",
"interval": "10m"
},
"aggregations": {
"errors": {
"avg": {
"field": "interface.out_error"
}
},
"thirtieth_difference": {
"serial_diff": {
"buckets_path": [
"errors"
]
}
}
}
}
}
}
}
}
}
}
Результат запроса:
{
"took": 23,
"timed_out": false,
"aggregations": {
"composite_agg": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"doc_count": 3540,
"interface": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 320,
"buckets": [
{
"doc_count": 320,
"key": "someinterface1",
"out_error": {
"buckets": [
{
"key_as_string": "2023-04-09T11:00:00.000Z",
"doc_count": 16,
"key": 1681038000000,
"errors": {
"value": 0
}
},
{
"key_as_string": "2023-04-09T11:10:00.000Z",
"doc_count": 160,
"thirtieth_difference": {
"value": 0
},
"key": 1681038600000,
"errors": {
"value": 0
}
},
{
"key_as_string": "2023-04-09T11:20:00.000Z",
"doc_count": 144,
"thirtieth_difference": {
"value": 0
},
"key": 1681039200000,
"errors": {
"value": 0
}
}
]
}
}
]
},
"key": "somecomposite1"
}
]
}
}
}
Есть ли параметр, который можно указать в запросе при агрегации, чтобы получить данные в разложенном виде, и, из "самой" вложенной агрегации доставать последний элемент в поле out_error? Примерно в таком виде:
{
"took": 23,
"timed_out": false,
"aggregations": {
"composite_agg": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"doc_count": 320,
"key": "someinterface1",
"composite_agg.key": "somecomposite1",
"composite_agg.doc_count": 3540,
"out_error": {
"thirtieth_difference": {
"value": 0
}
}
},
{
"doc_count": 123,
"key": "someinterfaceN",
"composite_agg.key": "somecompositeN",
"composite_agg.doc_count": 3540,
"out_error": {
"thirtieth_difference": {
"value": 0
}
}
}
]
}
}
}