Conditional clause not working


(Usha Rani) #1

Hi,
I have a scenario where I have to exclude range filter if price is not passed in the params to the template.
something like

{
"query": {
"bool": {
"must": {
"match": {
"name": "{{query_keywords}}"
}
},
"filter":{
"bool":{
"must" :[
{{#price}}
{"range" : {"price" : {"gte": "{{min}}","lte":"{{max}}}}}
{{/price}}
]
}
}

		}
	}

}

but I am not able to achieve this. so I am setting default value if price is not set like below
{
"query": {
"bool": {
"must": {
"match": {
"name": "{{query_keywords}}"
}
},
"filter":{
"bool":{
"must" :[
{"range" : {"price" : {"gte": "{{price.min}}{{^price.min}}0{{/price.min}}"}}}
]
}
}

		}
	}

}

This will hamper the performance in production. So can anyone suggest what has to be done. The example given the ES doc doesnt work. How to achieve this? Please help.


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.