How to write a conditional query with Elasticsearch? -


i have simple json query elasticsearch looks this:

"query": {   "bool": {     "must": { "match": { "id": "1" }} ,     "must": { "match": { "tags.name": "a1"}}    } } 

how can execute second 'must' criteria if value ('a1' in case) not empty?

you can achieve using following -

{   "query": {     "bool": {       "must": [         {           "match": {             "id": "1"           }         },         {           "bool": {             "should": [               {                 "missing": {                   "field": "tags.name"                 }               },               {                 "match": {                   "tags.name": "a1"                 }               }             ]           }         }       ]     }   } } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -