How to include given documents to my query that DONT match?

How would I include documents to my result (given _id's) when they DONT match the query?

example query:

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "purpose": {
              "value": "my_important_value_that_must_comply"
            }
          }
        }
      ]
    }
  }
}

resulting in all documents matching the above, but ALSO include documents in the (same?) result with given _id [1,2,3] (which dont match the criteria above)

How would I achieve this?

I'm running Elasticsearch version 5.5

Thanks in advance!

What about this?

A bool query with 2 should clauses:

  • One should clause is the term query you mentioned.
  • The other should clause would be a bool query with a
    • must clause which contains an id query
    • must_not clause which contains the term query you mentioned.

That is exactly what i'm looking for @dadoonet , thanks a whole lot!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.