What is the best way to use mustache False values feature in Elasticsearch template?
At the moment I am trying to select function based on boolean value.
Rendering seems to be working according to the logic, but it prints empty double quotes and I cannot get rid of those.
Code example:
Template snippet:
"must": {
"function_score": {
"functions": [
"{{^isLocationFunctionNeeded}}",
{
"exp": {
"location": {
"origin": {
"lat": "0.0",
"lon": "0.0"
},
"offset": "1km",
"scale": "50km"
}
}
},
"{{/isLocationFunctionNeeded}}",
{
"random_score": {},
"weight": 0.00001
}
],
"score_mode": "sum"
}
}
Render snippet:
"must": {
"function_score": {
"functions": [
"",
{
"random_score": {},
"weight": 1.0E-5
}
],
"score_mode": "sum"
}
}
Error I get trying to run the template on ELK:
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "failed to parse [START_OBJECT]. malformed query, expected a [VALUE_STRING] while parsing functions but got a [function_score] instead",
"line": x (where "" is visible in Render snippet),
"col": x (where "" is visible in Render snippet)
}
],
"type": "x_content_parse_exception",
"reason": " x (where "" is visible in Render snippet),[bool] failed to parse field [must]",
"caused_by": {
"type": "parsing_exception",
"reason": "failed to parse [START_OBJECT]. malformed query, expected a [VALUE_STRING] while parsing functions but got a [function_score] instead",
"line": x (where "" is visible in Render snippet),,
"col": x (where "" is visible in Render snippet),
}
Without mustache values it's working fine. Also I noticed in some cases if you surround empty double quotes with random functions it tends to work sometimes. Seems Elastic don't like must cases starting with empty double quotes.