Reputation: 7726
Let's say I have a doc format like this:
doc #1
A: 1
B: 2
C: 3
doc #2
A: 4
B: 1
C: 8
So, the user input will be 1. I do a multi_match query against A,B and C. This works fine. I want to consider A as the primary, so I gave it a boost (currently 5). That works fine and all the docs with A: 1 rise to the top.
However, given the two docs above, an input of "1" will return both docs. The way I want the search to work is to make A the priority field and if I find the value there, I want to disregard the two other fields.
If no A: 1's were found, then I want to search B&C as a fallback.
Does elasticsearch have a mechanism for this?
Here are the cases for input=1
Upvotes: 0
Views: 950
Reputation: 30163
Elasticsearch doesn't support such functionality. Even if it did, it wouldn't be significantly more optimal then you running the first query against A and if it doesn't return anything running the second query against B and C from the client.
In elasticsearch, search is distributed across multiple shards and the fact that a particular shard didn't find a document doesn't mean that this document doesn't exist in other shards. So, to implement it inside elasticsearch, we would have to execute the query for A first, check that it doesn't return anything and then execute the query for B and C. Moving this to the client just adds an additional hop between the client and the elasticsearch node to the process. Other than that, it's pretty much the same.
Upvotes: 3