Search code examples
elasticsearchfoselasticabundle

Elasticsearch - Search NOT IN


I got lot of documents defined nearly like that:

{
   "id": 1,
   "createdBy": 1379662
   "content": "foo"
}
{
   "id": 2,
   "createdBy": 549674
   "content": "bar"
}

I'm trying to get all documents where createdBy is not in a list:

{
  "post_filter":{
     "bool":{
        "must_not":[
           {
              "term":{
                 "createdBy":[
                    1379662,
                    18475
                 ]
              }
           }
        ]
     }
  },
  "query":{
     "match_all":{

     }
  }
}

But with that I still get the document create by 1379662. If I use only one value in my array, it's works

"term":{
    "createdBy":[1379662]
}

Were're using an old version of ES (1.7.5) on this project. But there is a solution?

Thanks for helping

Bouffe


Solution

  • Use terms instead of term

    {
      "post_filter":{
         "bool":{
            "must_not":[
               {
                  "terms":{               <--- change this
                     "createdBy":[
                        1379662,
                        18475
                     ]
                  }
               }
            ]
         }
      },
      "query":{
         "match_all":{
    
         }
      }
    }