Is it possible to pass a rich parameter structure into a body
template's rendering context?
See the "Non empty lists" section in the mustache docs for an example
of what I'm trying to do. http://mustache.github.com/mustache.5.html
Thanks.
Alex
Can you give a rough skeleton of the structure that you want to pass?
I think there is quick way, but I want to understand the use case
before I suggest it.
Subbu
Basically, I want to pass ElasticSearch query parameters into the template. Take the term query for example:
http://www.elasticsearch.org/guide/reference/query-dsl/term-query.html
I'd like to pass the "term" parameter is as { "user" : "kimchy" } or { "user" : { "value" : "kimchy", "boost" : 2.0 }. The same applies to a bunch of the other parameters that can be provided in an ElasticSearch query doc, such as "prefix", "text" and especially "range".
I'd prefer not to flatten these parameters out, if I can help it. Let me know if that doesn't make sense, or if there's a better way.
Alex
can be mapped to template
{
{{#params}}
"term": { "user": "{{user}}" }
{{/params}}
}
A snippet like
> { "user" : { "value" : "kimchy", "boost" : 2.0 }
can also be mapped similarly.
Mustache does have some limitations as it requires the data to be shaped to fit the template. If the data is not shaped, an alternative is to write a UDF to shape the data. For this, add a monkey patch (http://ql.io/docs/monkey-patch) that exports a function like the one below.
exports['udf'] = {
'user' : function(arg) {
return {
...some json here...
};
}
}
This can be triggered with
select * from foo where user('kimchy').
Even better alternative would be to support an alternative to Mustache like EJS. Thoughts?
Subbu
> Gotcha. It seems to me that having more robust templating would only be a good thing. Though, I'm not really using ql.io for anything "real" so I couldn't make a better case for it than that. :)
That's true - https://github.com/ql-io/ql.io/issues/130
Subbu