0

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

样本输入:

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

}

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

4

1 回答 1

0

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

像这样写:

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

            },
            "filter" : {
                "and" : {
                    "filters" : [{
                            "term" : {
                                "field1" : "val1"
                            }                           
                        }, {
                            "not" : {
                                "filter" : {
                                    "term" : {
                                        "field2" : "val2",
                                    }
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}
于 2014-06-17T07:56:27.543 回答