我试图迭代ElasticSearch Mustache模板中的多维参数,但我的代码不起作用。给定以下Elastic查询,参数为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}
]
}
}
我想先使用att
参数进行过滤,然后使用values
部分。下面是我的代码,它不工作。有人能帮我找出什么是错的吗:
{{#att}}
{
"bool" :
{
"should" : [
{{#values}}
{
"nested": {
"path": "nestedField",
"query": {
"bool": {
"must": [
{"match": {"att.value": "{{value}}"}},
{"match": {"att.code": "{{../code}}"}}]
}
}
}
}
{{^lastValue}}, {{/lastValue}}
{{/values}}
]
}
}{{^last}}, {{/last}}
{{/att}}
谢谢你的帮助。
更新:如果我尝试这个:(感谢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
}
]
};
它使用这个模板:
<h1>{{Subject}}</h1>
<ul>
{{#attributs}}
<li>{{code}}
<ul>{{#values}}
<li>{{code}} => {{value}}{{^lastValue}}, {{/lastValue}}</li>
{{/values}}
</ul>
{{^last}}, {{/last}}
</li>
{{/attributs}}
</ul>
为什么不在我的elasticsearch胡子模板中?
1条答案
按热度按时间r1wp621o1#
我终于解决了我的问题: