# Slow Wildcard searches are prioritized in Bool queries

**URL:** <https://discuss.elastic.co/t/slow-wildcard-searches-are-prioritized-in-bool-queries/347521>\
**Category:** Elasticsearch\
**Created:** [November 20, 2023, 10:07am UTC](https://discuss.elastic.co/t/slow-wildcard-searches-are-prioritized-in-bool-queries/347521 "2023-11-20T10:07:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ratinhoo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ratinhoo/32/127761_2.png) [@ratinhoo](https://discuss.elastic.co/u/ratinhoo)\
**Post date:** [November 20, 2023, 10:07am UTC](https://discuss.elastic.co/t/slow-wildcard-searches-are-prioritized-in-bool-queries/347521/1 "2023-11-20T10:07:10Z")

</div>

Hi,

we are dynamically generating bool queries that sometimes include wildcard searches. I understood that the execution order of bool queries is depending on term frequencies, document frequencies and other metrics. Problem is that depending on the search fields the wildcard queries are first in the execution order. This leads to really slow execution times, although it would be possible to filter most of the document out before executing the wildcard query.

Is there any possibility to adapt this execution order so that the wildcard queries are executed last or at least after the term queries oder does someone has another suggestion to handle this problem?

Also it is interesting that sometimes there is a difference in execution order between a term query and a terms query with the same input (so only one and the same element in the terms query). Is there a reason for that?

Thanks in advance.

---

<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:** [December 18, 2023, 10:07am UTC](https://discuss.elastic.co/t/slow-wildcard-searches-are-prioritized-in-bool-queries/347521/2 "2023-12-18T10:07:39Z")

</div>

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