Elastic search Not filter inside and filter
Asked Answered
P

1

0

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.

Provinciality answered 16/6, 2014 at 7:38 Comment(0)
P
0

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",
                                    }
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}
Ptarmigan answered 17/6, 2014 at 7:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.