gpt4 book ai didi

elasticsearch - ElasticSearch结合了MUST和MUST_NOT

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

我需要找到所有包含列表中给定ID且没有字段“device_data”的文档。

我的搜索查询:

{
"query": {
"bool" : {
"must" : [
{
"terms" : {
"id" : [
"1cbe0c01-6e0c-11e8-b79f-097b2a39b616"
]
}
}
],
"must_not" : [
{
"exists" : {
"field" : "device_data"
}
}
]
}
}
}

仍然返回此文档,我希望在该文档中找不到“device_data”。我究竟做错了什么?
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 4.9881625,
"hits": [
{
"_index": "iot_data",
"_type": "sensors_by_id",
"_id": "[\"1cbe0c01-6e0c-11e8-b79f-097b2a39b616\",\"1cbe0c00-6e0c-11e8-b79f-097b2a39b616\"]",
"_score": 4.9881625,
"_source": {
"field_id": "123",
"device_data": {
"comm_nr": "xxxx1",
"id": "542b9010-67b6-11e8-ab71-997fe8a668b8",
"tag": "",
"type": ""
},
"groups": "group-test",
"id": "1cbe0c01-6e0c-11e8-b79f-097b2a39b616",
"time": "1cbe0c00-6e0c-11e8-b79f-097b2a39b616",
"username": "group-test"
}
}
]
}
}

最佳答案

您需要使用一个终端字段,例如device_data.id:

    "must_not" : [
{
"nested": {
"path": "device_data",
"query": {
"exists" : {
"field" : "device_data.id"
}
}
}
}
]

关于elasticsearch - ElasticSearch结合了MUST和MUST_NOT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50811161/

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