# Elasticsearch conditional filter

**URL:** <https://discuss.elastic.co/t/elasticsearch-conditional-filter/198398>\
**Category:** Elasticsearch\
**Created:** [September 6, 2019, 10:15am UTC](https://discuss.elastic.co/t/elasticsearch-conditional-filter/198398 "2019-09-06T10:15:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgvarley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mgvarley/32/687_2.png) [@mgvarley](https://discuss.elastic.co/u/mgvarley)\
**Post date:** [September 6, 2019, 10:15am UTC](https://discuss.elastic.co/t/elasticsearch-conditional-filter/198398/1 "2019-09-06T10:15:43Z")

</div>

We have a use case where around 65% of our documents can be uniquely identified by a single field however we cannot guarantee that this will match, in which case we want to fall back to a complex full text search query using several other fields.

I am looking at options for wrapping this logic in a bool however I cannot see a way of instructing Elasticsearch to "try this first, if nothing is found then try this other query". If I wrap these 2 different queries in a should then presumably Elasticsearch will evaluate both even though one is very performant and the other less so. Alternatively I can split into 2 queries and hit Elasticsearch with the simple query and only call again if this does not find a match but then I incur the penalty of 2 HTTP calls.

Any advice on this would be very much appreciated!

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [September 8, 2019, 4:24pm UTC](https://discuss.elastic.co/t/elasticsearch-conditional-filter/198398/2 "2019-09-08T16:24:48Z")

</div>

Elasticsearch does not have this functionality. You'll need to send two separate requests to Elasticsearch.

---

<div class="post-metadata">

**Author:** ![mgvarley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mgvarley/32/687_2.png) [@mgvarley](https://discuss.elastic.co/u/mgvarley)\
**Post date:** [September 9, 2019, 11:28am UTC](https://discuss.elastic.co/t/elasticsearch-conditional-filter/198398/3 "2019-09-09T11:28:00Z")

</div>

Thank you for confirming Abdon, I thought that might be the case ✅

---

<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, 2019, 11:28am UTC](https://discuss.elastic.co/t/elasticsearch-conditional-filter/198398/4 "2019-10-07T11:28:01Z")

</div>

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