我正在尝试滤除Kibana中的错误,但不是所有错误,而是仅在消息字段中没有特定字符串的错误。我的查询如下:
GET search-apps/_search
{
"query": {
"bool": {
"filter": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"gte": "now-120m",
"lte": "now"
}
}
},
{
"term": {
"level": "error"
}
}
],
"must_not": [
{
"term": {
"message": "Exception thrown while fetching records from Kinesis"
}
}
]
}
}
}
}
}
似乎过滤器会忽略“must_not”,因为我仍然在message字段中收到包含该字符串的错误。是否有某种执行顺序忽略了must_not?必须工作正常,我只会返回level:error,但是我还会得到消息中包含该字符串的结果。
如果我只想返回带有消息字段的结果,这也可以工作:
{
"query": {
"match": {
"message": {
"query": "Exception thrown while fetching records from Kinesis",
"type": "phrase"
}
}
}
}
但是,相反的per this thread,不能按建议工作。
最佳答案
您的问题已经包含解决“问题”的方法。
在must_not
-子句中,您使用的是term
-query,用于测试完全匹配,而在“test”查询中,则是phrase
-query。如果您的消息包含短语,但还包含一些其他字节/文本,则term
-query不再匹配。
解决方案
只需在term
-query中将match_phrase
替换为bool
。
关于elasticsearch - ElasticSearch过滤器无法使用must AND must_not,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60117454/