Elasticsearch must_not 查询与正则表达式不匹配
Elasticsearch must_not query doesn't match regex
我想过滤掉 LogMessage 字段中存在 Too many connections
的所有文档。
我写的查询是:
'
{
"query": {
"bool": {
"must": {
"match": {
"logType": "Error"
}
},
"must_not": {
"match": {
"LogMessage": ".*Too many connections.*"
}
}
}
}
}'
另一方面,如果我在 LogMessage
字段中使用我的整个字符串,它工作正常。
我在这里验证了我的正则表达式:
https://regex101.com/r/EexTmV/1
请帮我解决这个问题。
您需要使用 regexp
query 而不是 match
查询
{
"query": {
"bool": {
"must": {
"match": {
"logType": "Error"
}
},
"must_not": {
"regexp": {
"LogMessage": ".*Too many connections.*"
}
}
}
}
}
我想过滤掉 LogMessage 字段中存在 Too many connections
的所有文档。
我写的查询是:
'
{
"query": {
"bool": {
"must": {
"match": {
"logType": "Error"
}
},
"must_not": {
"match": {
"LogMessage": ".*Too many connections.*"
}
}
}
}
}'
另一方面,如果我在 LogMessage
字段中使用我的整个字符串,它工作正常。
我在这里验证了我的正则表达式:
https://regex101.com/r/EexTmV/1
请帮我解决这个问题。
您需要使用 regexp
query 而不是 match
查询
{
"query": {
"bool": {
"must": {
"match": {
"logType": "Error"
}
},
"must_not": {
"regexp": {
"LogMessage": ".*Too many connections.*"
}
}
}
}
}