【问题标题】:Elastic search Not filter inside and filter弹性搜索不过滤内部和过滤
【发布时间】:2014-06-17 15:56:27
【问题描述】:

我正在尝试在“and”过滤器中添加一个“not”过滤器

示例输入:

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

}

但上面给出了错误,我也尝试了各种组合但徒劳无功。 以上只是一个简单的示例,我需要一个同时存在“and”、“not”过滤器的查询。

【问题讨论】:

    标签: lucene elasticsearch pyelasticsearch


    【解决方案1】:

    您忘记了“过滤器”数组。

    这样写:

    {
        "from" : 0,
        "size" : 25,
        "query" : {
            "filtered" : {
                "query" : {
                    "match_all" : {}
    
                },
                "filter" : {
                    "and" : {
                        "filters" : [{
                                "term" : {
                                    "field1" : "val1"
                                }                           
                            }, {
                                "not" : {
                                    "filter" : {
                                        "term" : {
                                            "field2" : "val2",
                                        }
                                    }
                                }
                            }
                        ]
                    }
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-25
      • 2012-11-07
      • 1970-01-01
      • 2015-11-20
      相关资源
      最近更新 更多