Я выполняю агрегацию запросов на основе некоторых полей, все работает нормально, но я хочу отсортировать результат агрегации на основе поля агрегации суммы, то есть выручкиRecovered_sum в порядке возрастания, я пробовал с суммой, но, похоже, ниже это не работает. документ в поиске elasti c и запрос, поэтому в основном записи должны быть отсортированы в соответствии со значением восстановленного дохода, которое должно быть отсортировано в порядке возрастания
{
"took": 9,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1.0,
"hits": [
{
"_index": "a4b7a825f67930965747445709011120-wip_index",
"_type": "recommendation",
"_id": "Nun2XnIB4lrUDhoMSc4j",
"_score": 1.0,
"_source": {
"id": "r2",
"clusterRank": null,
"recommendationRank": null,
"batchId": null,
"clusterId": "1",
"eventId": "1",
"exceptionId": "425567e9-d5d3-4347-84e2-67f2524c19dg",
"shipmentId": "123",
"shipmentHeaderId": "IS0101_SD_S3",
"eventType": "Delayed",
"item": "Item2",
"destinationLocation": "d1",
"dueDate": "2019-01-12T05:30:00.000+0530",
"exceptionQuantity": 50,
"recommendationType": "stockTransfer",
"customerName": "Walmart",
"primaryRecommendation": true,
"priority": 1,
"sourceLocation": "s1",
"transferQuantity": 40,
"shipDate": "2019-01-11T05:30:00.000+0530",
"arrivalDate": "2019-01-12T05:30:00.000+0530",
"transportMode": "m1",
"transferCost": 200.0,
"maxQtyAvailableForTransfer": 40,
"totalQtyAtSource": 40,
"operation": "Road-Item1-from-DC3-to-DC1",
"peggedStockDemandIds": [
"1",
"2"
],
"revenueRecovered": 10000.0
}
},
{
"_index": "a4b7a825f67930965747445709011120-wip_index",
"_type": "recommendation",
"_id": "9-mjXnIB4lrUDhoM7aKb",
"_score": 1.0,
"_source": {
"id": "r1",
"clusterRank": null,
"recommendationRank": null,
"batchId": null,
"clusterId": "1",
"eventId": "1",
"exceptionId": "425567e9-d5d3-4347-84e2-67f2524c19df",
"shipmentId": "123",
"shipmentHeaderId": "IS0101_SD_S2",
"eventType": "Delayed",
"item": "Item1",
"destinationLocation": "d1",
"dueDate": "2019-01-12T05:30:00.000+0530",
"exceptionQuantity": 50,
"recommendationType": "stockTransfer",
"customerName": "Walmart",
"primaryRecommendation": true,
"priority": 1,
"sourceLocation": "s1",
"transferQuantity": 40,
"shipDate": "2019-01-11T05:30:00.000+0530",
"arrivalDate": "2019-01-12T05:30:00.000+0530",
"transportMode": "m1",
"transferCost": 200.0,
"maxQtyAvailableForTransfer": 40,
"totalQtyAtSource": 40,
"operation": "Road-Item1-from-DC3-to-DC1",
"peggedStockDemandIds": [
"1",
"2"
],
"revenueRecovered": 10000.0
}
},
{
"_index": "a4b7a825f67930965747445709011120-wip_index",
"_type": "recommendation",
"_id": "U-n5XnIB4lrUDhoMWNBT",
"_score": 1.0,
"_source": {
"id": "r3",
"clusterRank": null,
"recommendationRank": null,
"batchId": null,
"clusterId": "1",
"eventId": "1",
"exceptionId": "425567e9-d5d3-4347-84e2-67f2524c19dh",
"shipmentId": "123",
"shipmentHeaderId": "IS0101_SD_S4",
"eventType": "Delayed",
"item": "Item3",
"destinationLocation": "d1",
"dueDate": "2019-01-12T05:30:00.000+0530",
"exceptionQuantity": 50,
"recommendationType": "stockTransfer",
"customerName": "Walmart",
"primaryRecommendation": true,
"priority": 1,
"sourceLocation": "s1",
"transferQuantity": 40,
"shipDate": "2019-01-11T05:30:00.000+0530",
"arrivalDate": "2019-01-12T05:30:00.000+0530",
"transportMode": "m1",
"transferCost": 200.0,
"maxQtyAvailableForTransfer": 40,
"totalQtyAtSource": 40,
"operation": "Road-Item1-from-DC3-to-DC1",
"peggedStockDemandIds": [
"1",
"2"
],
"revenueRecovered": 500.0
}
}
]
}
}
Запрос:
{
"size": 0,
"query": {
"bool": {
"filter": [
{
"terms": {
"shipmentHeaderId.keyword": [
"IS0101_SD_S2",
"IS0101_SD_S3",
"IS0101_SD_S4"
],
"boost": 1
}
},
{
"terms": {
"exceptionId.keyword": [
"425567e9-d5d3-4347-84e2-67f2524c19df",
"425567e9-d5d3-4347-84e2-67f2524c19dg",
"425567e9-d5d3-4347-84e2-67f2524c19dh"
],
"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"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}