Я новичок вasticsearch. У меня есть два документа с уникальными идентификаторами в моем документе, это ID-исключения, когда ИД-исключения равен 1, тогда он корректно возвращает агрегацию суммы для документа 1, но если я хочу агрегирование суммы обоих документов по отдельности, если мой input isceptionId 1 и 2, тогдаasticsearch выполнит суммирование обоих документов и вернет результат в моем случае для совпадающих входных данных, которое должно вернуть соответствующее агрегирование суммы документа, а если входные данные кратны, агрегация должна быть кратной.
Это отображение.
{
"mappings": {
"recommendations": {
"properties": {
"events": {
"type": "nested",
"properties": {
"recommendationData": {
"type": "nested",
"properties": {
"recommendations": {
"type": "nested",
"properties": {
"recommendationType": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
}
}
Это документ с exceptionId как "1"
{
"clusterId": "1",
"rank": 1,
"events": [
{
"eventId": "1",
"eventType": "Delayed",
"metaInfo": {
"batch_id": "batch_1"
},
"recommendationData": [
{
"exceptionId": "1",
"item": "KitKat",
"location": "DC1",
"dueDate": "2019-01-10T05:30:00.000+0530",
"quantity": 100,
"metaInfo": {
"batch_id": "batch_1",
"dummy_id": "dummy_1"
},
"rank": 1,
"recommendations": [
{
"rank": 1,
"recommendationType": "Out Of Stock",
"customerName": "Walmart",
"stockTransfer": {
"primaryRecommendation": true,
"priority": 1,
"sourceLocation": "DC1",
"transferQuantity": 100,
"metaInfo": 40,
"shipDate": "01/01/2020",
"arrivalDate": "10/01/2020",
"transportMode": "Air",
"transferCost": 1000,
"maxQtyAvailableForTransfer": 40,
"totalQtyAtSource": 1,
"revenueRecovered": 12000
},
"expedite": null
}
]
}
]
}
]
}
Это документ с exceptionId как "2"
{
"clusterId": "2",
"rank": 2,
"events": [
{
"eventId": "2",
"eventType": "Delayed",
"metaInfo": {
"batch_id": "batch_1"
},
"recommendationData": [
{
"exceptionId": "2",
"item": "KitKat",
"location": "DC1",
"dueDate": "2019-01-10T05:30:00.000+0530",
"quantity": 100,
"metaInfo": {
"batch_id": "batch_1",
"dummy_id": "dummy_1"
},
"rank": 1,
"recommendations": [
{
"rank": 1,
"recommendationType": "Out Of Stock",
"customerName": "Walmart",
"stockTransfer": {
"primaryRecommendation": true,
"priority": 1,
"sourceLocation": "DC1",
"transferQuantity": 100,
"metaInfo": 40,
"shipDate": "01/01/2020",
"arrivalDate": "10/01/2020",
"transportMode": "Air",
"transferCost": 1000,
"maxQtyAvailableForTransfer": 40,
"totalQtyAtSource": 1,
"revenueRecovered": 12000
},
"expedite": null
}
]
}
]
}
]
}
Это запрос, который я пробовал
{
"aggregations": {
"recommendations": {
"nested": {
"path": "events.recommendationData"
},
"aggregations": {
"exceptionId": {
"filter": {
"terms": {
"events.recommendationData.exceptionId": [
"1", "2"
],
"boost": 1
}
},
"aggregations": {
"by_item": {
"terms": {
"field": "events.recommendationData.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": {
"by_destination": {
"terms": {
"field": "events.recommendationData.location.keyword",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"recommendations": {
"nested": {
"path": "events.recommendationData.recommendations"
},
"aggregations": {
"by_trans": {
"terms": {
"field": "events.recommendationData.recommendations.stockTransfer.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": {
"by_sourcelocation": {
"terms": {
"field": "events.recommendationData.recommendations.stockTransfer.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": {
"by_shipdate": {
"terms": {
"field": "events.recommendationData.recommendations.stockTransfer.shipDate.keyword",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"by_arrival": {
"terms": {
"field": "events.recommendationData.recommendations.stockTransfer.arrivalDate.keyword",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"quantity": {
"sum": {
"field": "events.recommendationData.recommendations.stockTransfer.transferQuantity"
}
},
"transfercost": {
"sum": {
"field": "events.recommendationData.recommendations.stockTransfer.transferCost"
}
},
"revenueRecovered": {
"sum": {
"field": "events.recommendationData.recommendations.stockTransfer.revenueRecovered"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
Здесь выводится, что он выполняет все суммирование из документа 1 и документа 2
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.0,
"hits": []
},
"aggregations": {
"recommendations": {
"doc_count": 2,
"exceptionId": {
"doc_count": 2,
"by_item": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "KitKat",
"doc_count": 2,
"by_destination": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "DC1",
"doc_count": 2,
"recommendations": {
"doc_count": 2,
"by_trans": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Air",
"doc_count": 2,
"by_sourcelocation": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "DC1",
"doc_count": 2,
"by_shipdate": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "01/01/2020",
"doc_count": 2,
"by_arrival": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "10/01/2020",
"doc_count": 2,
"quantity": {
"value": 200.0
},
"transfercost": {
"value": 2000.0
},
"revenueRecovered": {
"value": 24000.0
}
}
]
}
}
]
}
}
]
}
}
]
}
}
}
]
}
}
]
}
}
}
}
}