-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug with mustache iterators when searching with array input #37333
Comments
Pinging @elastic/es-core-infra |
@maggieghamry I think all the examples you provided have to escape the double-quotes, since the mustache elements are not valid JSON elements. In any case, this would be a solution without using an additional parameter like in your example 4:
If you believe what I mentioned above is not the issue, do please provide more details about what you want to achieve. |
Thank you, @astefan . I was hoping to use one search template to drive two different searches. Because of this, the Ids need to be optional. So, the escaped template would look something like this, which returns the same error:
Error returned:
The objective is to use the search template for 2 types of searches. We have "policy" rules embedded in the template that are fairly complex and should be the same for both searches. First, we want to search by a list of identifiers. Secondly, a search where several fields can be used to search. Both should have the complex “policy” filters applied. We want to use one search template so we don’t have to maintain the complex policy rules in multiple places. |
Hi @maggieghamry @astefan The way I found around this is to check if the first item is not empty.
The output of which is:
Similarly, if the ids parameter isn't provided i.e.
The output is:
The only caveat is that if you leave an empty array in, it'll cause an index_out_of_bounds_exception i.e
As I said you probably found a solution to this, but good to have it documented here for others in the future. It'd be useful if this could be included in the elasticsearch documentation somewhere; I spent hours trying to find a solution to this. Cheers, |
Studying closelly mustache documentation I can see that this behavior is according to specification
As a workaround I would suggest to modify the input parameters structure to something like this "params":{
"ids": {
"values": [
"2473272002",
"1074568002"
]
}
} and template accordingly
This is probably the best you can get with mustache. Cheers |
6.5 (
bin/elasticsearch --version
):Description of the problem including expected versus actual behavior:
I have search templates that leverage array parameters. The examples below are simplified versions of a search template I am working on. The examples execute the GET
_render/template
endpoint with different inputs and then describe the outputs that returned.Steps to reproduce:
Example #1 - The following search template fails to render:
The error returned is:
Example #2 - Another way to write the original template is to use mustache iterators (https://github.com/mustache/spec/blob/master/specs/sections.yml#L141-L169)
Example #2 fails with the same error as Example #1.
Example #3 - Interestingly, if I add another query to the must clause the template validates with no errors.
Example #3 returns:
boolean
parameter that controls the rendering on the array parameter then the template will validate with no errors.Example #4 returns:
There appears to be a bug with how search templates handle array inputs. Examples #1 and #2 are valid mustache and should return results similar to example #4. Example #3 is identical to example #2 with an additional must query but returns the valid template output.
However, the output from example #3 and #4 are not the same. I would have expected example #3 to return:
The text was updated successfully, but these errors were encountered: