Template queries with params in Java API. Bug?

Hi,

I am trying to figure out issues with these kinds of queries when using the
Java API.

curl http://10.10.9.13:9200/global6/user/_search/template '{
"template": {
"query": {
"term": {
"{{field}}" : "{{value}}"
}
},
"aggs" : {
"{{field}}" :
{ "terms" : { "field": "{{field}}"} }
}
},
"params": {
"field" : "twuser.twuser.name",
"value" : "alexander"
}
}'

Unfortunately, the params don’t seem to work in template queries when used
via the Java API (without params the template works). I am building the
query like this (thanks Colin G):

getSearchRequestBuilder().setTemplateSource(Resources.toString(url,
Charset.forName("UTF-8"))).setTemplateParams(templateParams);

I think the problem lies here:

     org.elasticsearch.action.search.SearchRequest
    if (out.getVersion().onOrAfter(Version.V_1_1_0)) {
        out.writeBytesReference(templateSource);
        out.writeOptionalString(templateName);

        booleanexistTemplateParams = templateParams != null;
        out.writeBoolean(existTemplateParams);
        if (existTemplateParams) {
            out.writeGenericValue(templateParams);
        }
    }
}

As far as I can see the params don’t get added as a json map, although I’m
not entirely familiar with the format of transport messages.

Logs from the slow log on the server show an empty space where the
placeholder should be (e.g. "{{value}}" in the template above looks like
“”).

Is this a bug? If so happy to produce a patch. If not, any workaround would
be welcome - I’m currently just doing the templating myself.

Kind regards,

Luke

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/187eed4b-0ac4-42e0-9dfe-c2027b667b13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

It was just documented some days ago: Elasticsearch Platform — Find real-time answers at scale | Elastic

Could this help you? If not, please tell me what is missing or send a PR. :slight_smile:

David

Le 5 déc. 2014 à 11:32, Luke Wilson-Mawer lukewilsonmawer@gmail.com a écrit :

Hi,

I am trying to figure out issues with these kinds of queries when using the Java API.

curl http://10.10.9.13:9200/global6/user/_search/template '{
"template": {
"query": {
"term": {
"{{field}}" : "{{value}}"
}
},
"aggs" : {
"{{field}}" :
{ "terms" : { "field": "{{field}}"} }
}
},
"params": {
"field" : "twuser.twuser.name",
"value" : "alexander"
}
}'

Unfortunately, the params don’t seem to work in template queries when used via the Java API (without params the template works). I am building the query like this (thanks Colin G):

getSearchRequestBuilder().setTemplateSource(Resources.toString(url, Charset.forName("UTF-8"))).setTemplateParams(templateParams);

I think the problem lies here:

     org.elasticsearch.action.search.SearchRequest
    if (out.getVersion().onOrAfter(Version.V_1_1_0)) {
        out.writeBytesReference(templateSource);
        out.writeOptionalString(templateName);

        booleanexistTemplateParams = templateParams != null;
        out.writeBoolean(existTemplateParams);
        if (existTemplateParams) {
            out.writeGenericValue(templateParams);
        }
    }
}

As far as I can see the params don’t get added as a json map, although I’m not entirely familiar with the format of transport messages.

Logs from the slow log on the server show an empty space where the placeholder should be (e.g. "{{value}}" in the template above looks like “”).

Is this a bug? If so happy to produce a patch. If not, any workaround would be welcome - I’m currently just doing the templating myself.

Kind regards,

Luke

You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/187eed4b-0ac4-42e0-9dfe-c2027b667b13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/25673D45-D5CB-4C2B-B149-7F2B8CFDD73A%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.