这是我在 Elasticsearch 中使用的查询,用于过滤满足一个条件或不满足其他条件的记录。
{
"query":
{
"query_string":
{
"query": "(NOT col1: \"val1\") OR (col2: val2)",
"analyze_wildcard": true
}}}
问题是我无法在 Nodejs 中编写等效的语法来提取信息。我们不能在这里使用must_not,因为它是一个OR条件
最佳答案
您将在 should 数组中设置这两个条件,因为如果有人匹配您,您将在结果中获得记录,您将必须使用 must match
和 must_not match
{
"query": {
"bool": {
"should": [
{
"bool": {
"must_not": {
"match": {
"col1": {
"query": "val1",
"type": "phrase"
}
}
}
}
},
{
"match": {
"col2": {
"query": "val2",
"type": "phrase"
}
}
}
]
}
}
}
关于node.js - 在 Elastic 搜索中同时使用 NOT 和 OR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47546424/