3

I’d like to combine ids query with must_not clause. I’m using (re)tire gem with rails application.

I’m doing something like this:

query do
  ids ["foo", "bar", "test"]
end

Which works. However, when I’m trying to combine it with must_not clause, I’m getting error – must_not works only withing boolean scope, which does not include ids query. Is there any way to combine that two queries?

Surya
  • 15,703
  • 3
  • 51
  • 74
user1105595
  • 591
  • 2
  • 8
  • 20

1 Answers1

9

The ES query that you need to use is this one:

GET /some_index/some_type/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "ids": {
            "values": ["foo", "bar", "test"]
          }
        }
      ],
      "must_not": [
        {
          "match": {
            "name": "whatever"
          }
        }
      ]
    }
  }
}

So, you need boolean scope, a must with your ids and a must_not with your must not match queries.

Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89