shiva
shiva

Reputation: 51

Elastic Search - Conditional field query if no match found for another field

Is it possible to do conditional field query if match was not found for another field ?

for eg: if I have a 3 fields in the index local_rating , global_rating and default_rating , I need to first check in local_rating and if there is no match then try for global_rating and finally for default_rating .

is this possible to do with one query ? or any other ways to achieve this

thanks in advance

Upvotes: 0

Views: 345

Answers (1)

A l w a y s S u n n y
A l w a y s S u n n y

Reputation: 38502

Not sure about any existing features of Elasticsearh to fulfill your current requirements but you can try with fields and per-fields boosting, Individual fields can be boosted with the caret (^)notation. Also I don't know boosting is possible with numeric value or not?

 GET /_search
 {
  "query": {
  "multi_match" : {
   "query" : 10,
    "fields" : [ "local_rating^6", "global_rating^3","default_rating"] 
   }
  }
}

See: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#field-boost

Upvotes: 1

Related Questions