Reputation: 31
I have two queries for phrase match and tokenized match. I want tokenized match to trigger only if phrase match fails.
So query A=phrase match, query B=tokenized match.
GET /content_card/_search
{ "size":1000,
"track_total_hits": true,
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "The Chosen",
"fields": [
"title^9",
"original_title^9"
],
"type": "phrase_prefix",
"boost": 9
}},
{
"multi_match": {
"query": "The chosen",
"fields": [
"title^9",
"original_title^9",
"content_type^9",
"type^7",
"content_category^7",
"genres^7",
"lang_names^7",
"keywords^7",
"cast_names^7",
"crews^7",
"country_names^5",
"overview^5",
"company_names^5",
"network_names^5",
"additional_company_names^5",
"content_status^1",
"release_year^1",
"ratings^1",
"seasons_names^1",
"episodes_names^0",
"_charcters^1"
],
"type": "best_fields"
}
}
],
"minimum_should_match": 1
}
}
}
Simply using should makes result of query B to appear after finishing up showing results for query A. I want the query B result only as a fallback for query A. Can anyone please help in getting the solution of the query. If there are other approach also kindly let me know. below line are repeated to post the query
Upvotes: 2
Views: 303
Reputation: 32386
What you are looking is not possible in Elasticsearch, you don't have a conditional way of firing the query in Elasticsearch, this you need to handle in your application which is making these Elasticsearch query, it's simple to achieve, with every Elasticsearch query, no of search results are returned and if its 0, you can send your tokenized or second query.
Also looks like you got confused about boolean query/clause in Elasticsearch, refer official documentation which explains the concept with nice example for more info.
Upvotes: 1