Elasticsearch conditional filter

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!

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

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

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