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

**URL:** https://discuss.elastic.co/t/how-to-include-given-documents-to-my-query-that-dont-match/223327
**Category:** Elasticsearch
**Created:** [March 12, 2020, 12:44pm UTC](https://discuss.elastic.co/t/how-to-include-given-documents-to-my-query-that-dont-match/223327 "2020-03-12T12:44:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Bart\_de\_Man](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bart_de_man/32/48319_2.png) [@Bart\_de\_Man](https://discuss.elastic.co/u/Bart_de_Man)
#### Post date: [March 12, 2020, 12:44pm UTC](https://discuss.elastic.co/t/how-to-include-given-documents-to-my-query-that-dont-match/223327/1 "2020-03-12T12:44:15Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 12, 2020, 1:26pm UTC](https://discuss.elastic.co/t/how-to-include-given-documents-to-my-query-that-dont-match/223327/2 "2020-03-12T13:26:59Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Bart\_de\_Man](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bart_de_man/32/48319_2.png) [@Bart\_de\_Man](https://discuss.elastic.co/u/Bart_de_Man)
#### Post date: [March 12, 2020, 2:47pm UTC](https://discuss.elastic.co/t/how-to-include-given-documents-to-my-query-that-dont-match/223327/3 "2020-03-12T14:47:53Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 9, 2020, 2:48pm UTC](https://discuss.elastic.co/t/how-to-include-given-documents-to-my-query-that-dont-match/223327/4 "2020-04-09T14:48:02Z")

</div>

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