# Very slow performance of must\_not with exists in filter

**URL:** https://discuss.elastic.co/t/very-slow-performance-of-must-not-with-exists-in-filter/144281
**Category:** Elasticsearch
**Created:** [August 14, 2018, 6:37am UTC](https://discuss.elastic.co/t/very-slow-performance-of-must-not-with-exists-in-filter/144281 "2018-08-14T06:37:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ShilpiRachna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shilpirachna/32/42261_2.png) [@ShilpiRachna](https://discuss.elastic.co/u/ShilpiRachna)
#### Post date: [August 14, 2018, 6:37am UTC](https://discuss.elastic.co/t/very-slow-performance-of-must-not-with-exists-in-filter/144281/1 "2018-08-14T06:37:06Z")

</div>

Hi,

We are investigating some slow queries in our Prod environment. We saw that the following filter is much slower than other term queries in query / filter section.

"query": {  
"bool": {  
"must": {…},  
"filter" : {  
"should": [  
{  
"bool": {  
"must\_not": [  
{  
"exists": {  
"field": "isDiscussionOnly"  
}  
}  
]  
}  
},  
{  
"terms": {  
"isDiscussionOnly": [  
"false"  
]  
}  
}  
]  
}  
}  
}

Is there any known performance issue / performance guideline around using must\_not with exists.

Would it help to always have this field set (with some default value) and replace the above filter with term query filter?

---

<div class="post-metadata">

### Author: ![jaddison](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jaddison](https://discuss.elastic.co/u/jaddison)
#### Post date: [September 9, 2018, 9:22pm UTC](https://discuss.elastic.co/t/very-slow-performance-of-must-not-with-exists-in-filter/144281/2 "2018-09-09T21:22:49Z")

</div>

If you format/indent your code, it makes it easier for people to answer.

Perhaps the discussion in this [Github issue](https://github.com/elastic/elasticsearch/issues/22657) would be helpful?

---

<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: [October 7, 2018, 9:22pm UTC](https://discuss.elastic.co/t/very-slow-performance-of-must-not-with-exists-in-filter/144281/3 "2018-10-07T21:22:50Z")

</div>

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