gpt4 book ai didi

elasticsearch - Elasticsearch 如何使用不得在过滤器内查询

转载 作者:行者123 更新时间:2023-12-03 01:17:39 24 4
gpt4 key购买 nike

我下面有搜索查询和文档,如何使用一定不能查询。场景是针对匹配的货件ID,它必须提取文档,并且只要在 flex 搜索和搜索查询中的ID下面是ID匹配,就必须忽略文档。

文件

{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1.0,
"hits": [
{
"_index": "testing",
"_type": "recommendations",
"_id": "HkXEBnIB9OMCvyNvPDr-",
"_score": 1.0,
"_source": {
"id": "4d6b421b-c237-44b4-83d4-27bdcb26f8f2",
"clusterRank": null,
"recommendationRank": null,
"batchId": null,
"clusterId": "1",
"eventId": "1",
"exceptionId": "1",
"shipmentId": "123",
"eventType": "Delayed",
"item": "Item1",
"destinationLocation": "DC1",
"dueDate": "2019-01-12T05:30:00.000+0530",
"exceptionQuantity": 50,
"recommendationType": "stockTransfer",
"customerName": "Walmart",
"primaryRecommendation": true,
"priority": 1,
"sourceLocation": "DC3",
"transferQuantity": 40,
"shipDate": "2019-01-11T05:30:00.000+0530",
"arrivalDate": "2019-01-12T05:30:00.000+0530",
"transportMode": "Road",
"transferCost": 200.0,
"maxQtyAvailableForTransfer": 40,
"totalQtyAtSource": 40,
"operation": "Road-Item1-from-DC3-to-DC1",
"peggedStockDemandIds": null,
"revenueRecovered": 20000.0
}
},
{
"_index": "testing",
"_type": "recommendations",
"_id": "HUXEBnIB9OMCvyNvPDr-",
"_score": 1.0,
"_source": {
"id": "12d19e4e-90de-42e6-a6e6-cb83407cfcfb",
"clusterRank": null,
"recommendationRank": null,
"batchId": null,
"clusterId": "1",
"eventId": "1",
"exceptionId": "1",
"shipmentId": "1234",
"eventType": "Delayed",
"item": "Item1",
"destinationLocation": "DC1",
"dueDate": "2019-01-10T05:30:00.000+0530",
"exceptionQuantity": 100,
"recommendationType": "stockTransfer",
"customerName": "Walmart",
"primaryRecommendation": true,
"priority": 1,
"sourceLocation": "DC2",
"transferQuantity": 30,
"shipDate": "2019-01-09T05:30:00.000+0530",
"arrivalDate": "2019-01-10T05:30:00.000+0530",
"transportMode": "Road",
"transferCost": 300.0,
"maxQtyAvailableForTransfer": 30,
"totalQtyAtSource": 40,
"operation": "Road-Item1-from-DC2-to-DC1",
"peggedStockDemandIds": null,
"revenueRecovered": 15000.0
}
},
{
"_index": "testing",
"_type": "recommendations",
"_id": "H0XEBnIB9OMCvyNvPDr-",
"_score": 1.0,
"_source": {
"id": "c49c4440-dad6-4692-8ff0-ab4884f76ffe",
"clusterRank": null,
"recommendationRank": null,
"batchId": null,
"clusterId": "1",
"eventId": "1",
"exceptionId": "1",
"shipmentId": "123",
"eventType": "Delayed",
"item": "Item1",
"destinationLocation": "DC1",
"dueDate": "2019-01-12T05:30:00.000+0530",
"exceptionQuantity": 50,
"recommendationType": "stockTransfer",
"customerName": "Walmart",
"primaryRecommendation": true,
"priority": 2,
"sourceLocation": "DC2",
"transferQuantity": 10,
"shipDate": "2019-01-11T05:30:00.000+0530",
"arrivalDate": "2019-01-12T05:30:00.000+0530",
"transportMode": "Road",
"transferCost": 100.0,
"maxQtyAvailableForTransfer": 40,
"totalQtyAtSource": 40,
"operation": "Road-Item1-from-DC2-to-DC1",
"peggedStockDemandIds": null,
"revenueRecovered": 5000.0
}
}
]
}
}

搜索查询:
{
"size": 0,
"aggregations": {
"shippmentIdsMatch": {
"filter": {
"terms": {
"shipmentId.keyword": [
"1234"
],
"boost": 1
}
}
},
"query": {
"bool": {
"must_not": [
{
"term": {
"id.keyword": "1"
}
}
]
},
"aggregations": {
"by_shipmentId": {
"terms": {
"field": "shipmentId.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_exceptionId": {
"terms": {
"field": "exceptionId.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_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": {
"by_destination": {
"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": {
"by_trans": {
"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": {
"by_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": {
"by_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": {
"by_arrival": {
"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": {
"quantity": {
"sum": {
"field": "transferQuantity"
}
},
"transfercost": {
"sum": {
"field": "transferCost"
}
},
"revenueRecovered": {
"sum": {
"field": "revenueRecovered"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}

响应:
{
"error": {
"root_cause": [
{
"type": "named_object_not_found_exception",
"reason": "[15:21] unable to parse BaseAggregationBuilder with name [bool]: parser not found"
}
],
"type": "named_object_not_found_exception",
"reason": "[15:21] unable to parse BaseAggregationBuilder with name [bool]: parser not found"
},
"status": 400
}

最佳答案

您无法在query部分中包含aggregations ...因此不确定如何构建它。 queryaggregations是 sibling ,因此原则上您应该具有以下内容:

{
"size": 0,
"query": { <--- query part starts here
"bool": {
"must_not": [
{
"term": {
"id.keyword": "1"
}
}
]
}
},
"aggregations": { <--- sibling aggregation part starts here
"shippmentIdsMatch": {
"filter": {
"terms": {
"shipmentId.keyword": [
"1234"
],
"boost": 1
}
},
...

关于elasticsearch - Elasticsearch 如何使用不得在过滤器内查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61744967/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com