# How to use bool query with both "missing" and exists?

**URL:** https://discuss.elastic.co/t/how-to-use-bool-query-with-both-missing-and-exists/54467
**Category:** Elasticsearch
**Created:** [June 30, 2016, 8:08pm UTC](https://discuss.elastic.co/t/how-to-use-bool-query-with-both-missing-and-exists/54467 "2016-06-30T20:08:50Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![esamudio](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@esamudio](https://discuss.elastic.co/u/esamudio)
#### Post date: [June 30, 2016, 8:08pm UTC](https://discuss.elastic.co/t/how-to-use-bool-query-with-both-missing-and-exists/54467/1 "2016-06-30T20:08:50Z")

</div>

How would I format a bool query to use both the "exists" and the "missing" (must\_not & exists) combined in a single query?

I'm trying to stay away from deprecated filters...

In that same note, how exactly does the missing query work? I have a large dataset and I want to perform an operation on new data every day to add a few new fields to each record. If I have 99.9% (exaggerating for the sake of example) with the new fields and only .1% is new, would it still take a long time filtering through everything?

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [July 4, 2016, 7:44am UTC](https://discuss.elastic.co/t/how-to-use-bool-query-with-both-missing-and-exists/54467/2 "2016-07-04T07:44:32Z")

</div>

Hey,

the filters are not deprecated, they have been moved. If you use a bool query, you can now set a filter clause inside of that

```auto
"bool": {
  "must": [...],
  "should": [...],
  "must_not": [...],
  "filter" : [...]
}

```

See the docs on that [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html)

Here is some documentation how exists/missing works under the hood (by also indexing the field names and not only the values): [https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-field-names-field.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-field-names-field.html) (and here is the PR adding it [https://github.com/elastic/elasticsearch/pull/6269](https://github.com/elastic/elasticsearch/pull/6269))

--Alex

---

<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: [July 5, 2017, 10:38pm UTC](https://discuss.elastic.co/t/how-to-use-bool-query-with-both-missing-and-exists/54467/3 "2017-07-05T22:38:35Z")

</div>


