Bool搜索:must_not无效

时间:2018-03-15 07:48:54

标签: search kibana devtools

我使用bool进行搜索,就像这样:

{"query": {
    "bool": {
        "must": {
            "match": {
                "message": {
                    "query": "disconnect"
                }
            }
        },
        "must": {
            "match": {
                "message": {
                    "query": "server"
                }
            }
        },
        "must_not": {
            "match": {
                "message": {
                    "query": "pomelo_list"
                }
            }
        },
        "must_not": {
            "match": {
                "message": {
                    "query": "socket"
                }
            }
        },
        "filter": {
      "range": { "@timestamp": { "gte": "2018-03-15T07:21:56.950Z" }} 
    }
    }
}

}

结果如下: enter image description here

我们可以看到哪个doc包含“pomelo_list”,结果 为什么must_not没用? 如何才能使搜索结果正确?

1 个答案:

答案 0 :(得分:0)

首先,必须必须 - 不需要是数组。

其次你需要使用query_string

{"query": {
"bool": {
    "must": [{
        "match": {
            "message": {
                "query": "disconnect"
            }
        }
    },        
        "match": {
            "message": {
                "query": "server"
            }
        }
    ],
    "must_not": [{"query_string" : {
        "fields" : ["message"],
        "query" : "*pomelo_list*"
    }
    },       
        "match": {
            "message": {
                "query": "socket"
            }
        }
    ],
    "filter": {
  "range": { "@timestamp": { "gte": "2018-03-15T07:21:56.950Z" }} 
}
}

}

相关问题