We want to write an Elasticsearch search template something like following :
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"variable1": "{{value1}}"
}
},
{
"or" : [
{
"term" : {
"variable2" : "{{value2}}"
}
},
{
"{{value2}}" is null
}
]
}
]
}
}
}
}
}
I am aware that the part where I wrote "{{value2}}" is null
is invalid syntax. The result we want to achieve is that if the {{value2}} param passed to the search template is null then the search should only be filtered based on variable1 . So to achieve this kind of result how can I frame the query in ES ?