I am trying to iterate through a multidimensional param in an ElasticSearch Mustache template, but my code is not working. Given the following Elastic query with param att
:
GET my_idx/_search/template
{
"id": "my_template",
"params": {
"att" : [
{"code":"epi", "values" : [{ "value":"glove"}, {"value":"hat","lastValue":true}]},
{"code":"color", "values": [{"value":"Black"}, {"value":"White", "lastValue":true},
"last":true}
]
}
}
I would like to filter using the att
param first and then the values
section. Below is my code, which is not working. Can someone please help me identify what is wrong:
{{#att}}
{
"bool" :
{
"should" : [
{{#values}}
{
"nested": {
"path": "nestedField",
"query": {
"bool": {
"must": [
{"match": {"att.value": "{{value}}"}},
{"match": {"att.code": "{{../code}}"}}]
}
}
}
}
{{^lastValue}}, {{/lastValue}}
{{/values}}
]
}
}{{^last}}, {{/last}}
{{/att}}
Thank you for your help.
UPDATE : If I try this : (thanks to https://codepen.io/johnsonshara/pen/mPzbBO
var data = {
"Subject": "Template Engines",
"attributs": [{
"code": "enduction",
"values": [{
"value": "Paume et doigts"
}, {
"value": "Non Enduit",
"lastValue": true
}
]
}, {
"code": "coloris",
"values": [{
"value": "Noir"
}, {
"value": "Blanc",
"lastValue": true
}
],
"last": true
}
]
};
and it works with this template :
<h1>{{Subject}}</h1>
<ul>
{{#attributs}}
<li>{{code}}
<ul>{{#values}}
<li>{{code}} => {{value}}{{^lastValue}}, {{/lastValue}}</li>
{{/values}}
</ul>
{{^last}}, {{/last}}
</li>
{{/attributs}}
</ul>
Why not in my elasticsearch mustache template ?
I finally solved my problem :
{{#att}}
{
"bool" :
{
"should" : [
{{#values}}
{
"nested": {
"path": "nestedField",
"query": {
"bool": {
"must": [
{"match": {"att.value": "{{value}}"}},
{"match": {"att.code": "{{../code}}"}}]
}
}
}
}
{{^lastValue}}, {{/lastValue}}
{{/values}}
]
}
}{{^last}}, {{/last}} <---- delete this (in my special case)
{{/att}}