弹性搜索不过滤和过滤 [英] Elastic search Not filter inside and filter

查看:113
本文介绍了弹性搜索不过滤和过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在和过滤器



中添加一个not过滤器样本输入:

  {
query:{
filtered:{
query:{
query_string:{
query:error,
fields:[
request
]
}
},
filter
和:[
{
条款:{
hashtag:[
br2
]
},
not:{
terms:{
hashtag:[
br1
]
}
}
}
]
}
}
}
},

}
pre>

但以上是给出错误,我也尝试了各种组合,但徒劳无功。
以上只是一个例子,我需要一个查询,其中包含和,not过滤器。

解决方案

你忘记了filters数组。



写这样:

  {
from:0,
size:25,
query:{
filtered:{
查询:{
match_all:{}

},
过滤器:{
和:{
filters [{
term:{
field1:val1
}
},{
not:{
filter :{
term:{
field2:val2,
}
}
}
}
]
}
}
}
}
}


I am trying to add a "not" filter inside "and" filter

Sample input:

{
   "query":{
      "filtered":{
         "query":{
            "query_string":{
               "query":"error",
               "fields":[
                  "request"
               ]
            }
         },
         "filter":{
            and:[
               {
                  "terms":{
                     "hashtag":[
                        "br2"
                     ]
                  },
                  "not":{
                     "terms":{
                        "hashtag":[
                           "br1"
                        ]
                     }
                  }
               }
            ]
         }
      }
   }
},

}

But above is giving error, i also tried various combination but in vain. Above is just an example in short i require a query in which both "and", "not" filter are present.

解决方案

you forgot the "filters" array.

Write it like this :

{
    "from" : 0,
    "size" : 25,
    "query" : {
        "filtered" : {
            "query" : {
                "match_all" : {}

            },
            "filter" : {
                "and" : {
                    "filters" : [{
                            "term" : {
                                "field1" : "val1"
                            }                           
                        }, {
                            "not" : {
                                "filter" : {
                                    "term" : {
                                        "field2" : "val2",
                                    }
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}

这篇关于弹性搜索不过滤和过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆