Pass an array of integers to ElasticSeach template

女生的网名这么多〃 提交于 2020-01-06 19:34:27

问题


I am trying to pass an array of integers to ElasticSearch template using the below mustache template.

{{#filter5_terms}} 
"terms": {
"{{filter5_name}}": [
"{{#filter5_lt}}", 
"{{.}}",                                
"{{/filter5_lt}}"  ]
}
{{/filter5_terms}}

Above works, If I pass a string array (Ex: ["A","B"]. But the same is failing with the int array [1,2] with Nested: NumberFormatException[For input string: ""]; error.

Reference: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-template.html#_passing_an_array_of_strings

Can you please let me know if I am missing anything?

Thanks Anil


回答1:


I did fix this. We can use the below to replace the integer array into ElasticSearch query.

"terms": {
"{{filter5_name}}": {{filter5_lt}}
}

ElasticSearch documentation has an example to replace string arrays and I tried to use the same for integer arrays and it did not work.

So I had to use the above which is provided in Mustache templating examples.

Thanks Anil




回答2:


You really shouldn't rely on that, as the format is an inner implementation of Mustache and thus, subject to change. For example, if you try to emulate that using mustache.js, you'll get something like:

"terms: {
  "property": 3,4
}

To workaround this problem, you should add square brackets to the templated values. So, your example becomes:

"terms": {
  "{{filter5_name}}": [{{filter5_lt}}]
}

And that will get you what you want.

At least, this is true in mustache.js 2.2.1



来源:https://stackoverflow.com/questions/26919496/pass-an-array-of-integers-to-elasticseach-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!