У меня есть запрос ниже, в котором используется агрегатор самых популярных. Мне нужно отсортировать поле yieldRecovered_sum по возрастанию или убыванию. Я пытался разместить поле «order» с помощью «as c», но, похоже, оно не работает в поле «yieldRecovered_sum», как я могу отсортировать поле yieldRecovered_sum в запросе ниже. попробовал с сортировкой по сумме, но похоже, что это не рабочий запрос, который я добавил после исходного запроса
{
"size": 0,
"query": {
"bool": {
"filter": [
{
"terms": {
"shipmentHeaderId.keyword": [
"IS0101_SD_S2",
"IS0101_SD_S3"
],
"boost": 1
}
},
{
"terms": {
"exceptionId.keyword": [
"425567e9-d5d3-4347-84e2-67f2524c19df",
"425567e9-d5d3-4347-84e2-67f2524c19dg"
],
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggregations": {
"item": {
"terms": {
"field": "item.keyword",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"destinationLocation": {
"terms": {
"field": "destinationLocation.keyword",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"transportMode": {
"terms": {
"field": "transportMode.keyword",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"sourceLocation": {
"terms": {
"field": "sourceLocation.keyword",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"shipDate": {
"terms": {
"field": "shipDate",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"arrivalDate": {
"terms": {
"field": "arrivalDate",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"my_hits": {
"top_hits": {
"from": 0,
"size": 100,
"version": false,
"explain": false,
"_source": {
"includes": [
"id"
],
"excludes": []
}
}
},
"transferCost_sum": {
"sum": {
"field": "transferCost"
}
},
"transferQuantity_sum": {
"sum": {
"field": "transferQuantity"
}
},
"revenueRecovered_sum": {
"sum": {
"field": "revenueRecovered"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
Запрос с сортировкой по сумме:
{
"size": 0,
"query": {
"bool": {
"filter": [
{
"terms": {
"shipmentHeaderId.keyword": [
"IS0101_SD_S2",
"IS0101_SD_S3"
],
"boost": 1
}
},
{
"terms": {
"exceptionId.keyword": [
"425567e9-d5d3-4347-84e2-67f2524c19df",
"425567e9-d5d3-4347-84e2-67f2524c19dg"
],
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggregations": {
"item": {
"terms": {
"field": "item.keyword",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"destinationLocation": {
"terms": {
"field": "destinationLocation.keyword",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"transportMode": {
"terms": {
"field": "transportMode.keyword",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"sourceLocation": {
"terms": {
"field": "sourceLocation.keyword",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"shipDate": {
"terms": {
"field": "shipDate",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"arrivalDate": {
"terms": {
"field": "arrivalDate",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"my_hits": {
"top_hits": {
"from": 0,
"size": 100,
"version": false,
"explain": false,
"_source": {
"includes": [
"id"
],
"excludes": []
}
}
},
"transferCost_sum": {
"sum": {
"field": "transferCost"
}
},
"transferQuantity_sum": {
"sum": {
"field": "transferQuantity"
}
},
"revenueRecovered_sum": {
"sum": {
"field": "revenueRecovered"
}
},
"sum-bucket-sort": {
"bucket_sort": {
"sort": [
{
"revenueRecovered_sum": {
"order": "asc"
}
}
],
"size": 1
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}