{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/9711","repository_url":"https://api.github.com/repos/elastic/elasticsearch","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/9711/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/9711/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/9711/events","html_url":"https://github.com/elastic/elasticsearch/issues/9711","id":57823623,"number":9711,"title":"[Query DSL] Do not consider empty object at the end of array invalid token","user":{"login":"lukas-vlcek","id":205174,"avatar_url":"https://avatars.githubusercontent.com/u/205174?v=3","gravatar_id":"","url":"https://api.github.com/users/lukas-vlcek","html_url":"https://github.com/lukas-vlcek","followers_url":"https://api.github.com/users/lukas-vlcek/followers","following_url":"https://api.github.com/users/lukas-vlcek/following{/other_user}","gists_url":"https://api.github.com/users/lukas-vlcek/gists{/gist_id}","starred_url":"https://api.github.com/users/lukas-vlcek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukas-vlcek/subscriptions","organizations_url":"https://api.github.com/users/lukas-vlcek/orgs","repos_url":"https://api.github.com/users/lukas-vlcek/repos","events_url":"https://api.github.com/users/lukas-vlcek/events{/privacy}","received_events_url":"https://api.github.com/users/lukas-vlcek/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2015-02-16T16:21:23Z","updated_at":"2016-09-09T11:07:18Z","closed_at":"2015-02-27T23:42:12Z","body":"This might sound weird at start but I actually think is very useful feature, thus filling ticket to keep it around.\r\n\r\nWhen I use search templates it can happen that I need to populate something from parameter that is an array. In some situations this can lead to challenging situation in Query DSL. For example, imagine I need to pass in an array of tags that goes to `or` filter:\r\n\r\n    \"filter\": {\r\n        \"or\": [\r\n            { \"term\": { \"tag\": \"param_value1\" }},\r\n            { \"term\": { \"tag\": \"param_value2\" }},\r\n            ...\r\n            { \"term\": { \"tag\": \"param_valueN\" }}\r\n        ]\r\n    }\r\n\r\nGenerating such output from Mustache template does not seem to be easy to me. There are some tricky parts that need to be handled correctly. First, it is not easy to omit whole `or` filter part (or even whole `filter` part in this case) if tags array is empty. Secondly, we need to omit comma after the last element in the array. The best I have come up with so far is the following template:\r\n\r\n    \"filter\": { \"or\": [ {{#tags}} { \"term\": { \"tag\": \"{{.}}\" }}, {{/tags}} {} ] }\r\n\r\nThis results into the following output:\r\n\r\n    \"filter\": {\r\n        \"or\": [\r\n            { \"term\": { \"tag\": \"param_value1\" }},\r\n            { \"term\": { \"tag\": \"param_value2\" }},\r\n            ...\r\n            { \"term\": { \"tag\": \"param_valueN\" }},\r\n            {}\r\n        ]\r\n    }\r\n\r\nIf the `tags` parameter is empty or missing then it will result into the following:\r\n\r\n    \"filter\": {\r\n        \"or\": [\r\n            {}\r\n        ]\r\n    }\r\n\r\nIgnoring the `{}` token greatly simplify Mustache templating. May be ES is already intelligently doing this but I am not sure if this was intentional or just a luck. If the later I would like to suggest making it an official feature and part of \"official\" Query DSL grammar.\r\n\r\nHope this makes sense."},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments/245884514","html_url":"https://github.com/elastic/elasticsearch/issues/9711#issuecomment-245884514","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/9711","id":245884514,"user":{"login":"clintongormley","id":56599,"avatar_url":"https://avatars.githubusercontent.com/u/56599?v=3","gravatar_id":"","url":"https://api.github.com/users/clintongormley","html_url":"https://github.com/clintongormley","followers_url":"https://api.github.com/users/clintongormley/followers","following_url":"https://api.github.com/users/clintongormley/following{/other_user}","gists_url":"https://api.github.com/users/clintongormley/gists{/gist_id}","starred_url":"https://api.github.com/users/clintongormley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clintongormley/subscriptions","organizations_url":"https://api.github.com/users/clintongormley/orgs","repos_url":"https://api.github.com/users/clintongormley/repos","events_url":"https://api.github.com/users/clintongormley/events{/privacy}","received_events_url":"https://api.github.com/users/clintongormley/received_events","type":"User","site_admin":false},"created_at":"2016-09-09T11:07:18Z","updated_at":"2016-09-09T11:07:18Z","body":"thanks @lukas-vlcek - fixed"}}
{"actor":{"display_login":"clintongormley"}}