Pre-Registered Templates & Java API & passing collection to param

Hello Group,

I´m facing a problem with pre-registered templates. I´m able to store them,
and I´m able to call them via REST (passing params) - everything works like
a charm :slight_smile:
But using the Java-API there is a problem: the setTemplateParams method
only accepts a Map<String, String> as a parameter.

I want to pass a collection of numbers to my tempate in order to get a
result, without success, because i need to pass a Map<String, Object> to my
SearchRequestBuilder.

I´ve found this (this is similar to what I´m looking
for): https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/index/query/TemplateQueryTest.java#L393

Map<String, Object> arrayTemplateParams = new HashMap<>();
String[] fieldParams = {"foo","bar"};
arrayTemplateParams.put("fieldParam", fieldParams);

SearchResponse searchResponse =
client().prepareSearch("test").setTypes("type").setTemplateName("/mustache/4").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(arrayTemplateParams).get();
assertHitCount(searchResponse, 5);

Not in version 1.4.2 nor in 1.4.3-SNAPSHOT the method signature have
changed. So how can I pass (not string) collections to my template?

Cheers,
Rafael

--
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/99aac531-20e7-44c5-821f-e04b4f7b9f38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I’m afraid you can not as this fix has been only applied in master and 1.x.
Fix SearchRequest.templateParams so that it is a Map<String, Object> … · elastic/elasticsearch@fda1576 · GitHub https://github.com/elasticsearch/elasticsearch/commit/fda1576d55fdd56fd44df6d4608dca74d33d1536
Fix SearchRequest.templateParams so that it is a Map<String, Object> … · elastic/elasticsearch@350a2db · GitHub https://github.com/elasticsearch/elasticsearch/commit/350a2db8dfcaee134f85c8d8419970812a49ea2c

So it will be available in 1.5.

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr https://twitter.com/elasticsearchfr | @scrutmydocs https://twitter.com/scrutmydocs

Le 19 janv. 2015 à 09:54, Rafael Kubina rafael.kubina@gmail.com a écrit :

Hello Group,

I´m facing a problem with pre-registered templates. I´m able to store them, and I´m able to call them via REST (passing params) - everything works like a charm :slight_smile:
But using the Java-API there is a problem: the setTemplateParams method only accepts a Map<String, String> as a parameter.

I want to pass a collection of numbers to my tempate in order to get a result, without success, because i need to pass a Map<String, Object> to my SearchRequestBuilder.

I´ve found this (this is similar to what I´m looking for): https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/index/query/TemplateQueryTest.java#L393

Map<String, Object> arrayTemplateParams = new HashMap<>();
String fieldParams = {"foo","bar"};
arrayTemplateParams.put("fieldParam", fieldParams);

SearchResponse searchResponse = client().prepareSearch("test").setTypes("type").setTemplateName("/mustache/4").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(arrayTemplateParams).get();
assertHitCount(searchResponse, 5);

Not in version 1.4.2 nor in 1.4.3-SNAPSHOT the method signature have changed. So how can I pass (not string) collections to my template?

Cheers,
Rafael

--
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 mailto:elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/99aac531-20e7-44c5-821f-e04b4f7b9f38%40googlegroups.com https://groups.google.com/d/msgid/elasticsearch/99aac531-20e7-44c5-821f-e04b4f7b9f38%40googlegroups.com?utm_medium=email&utm_source=footer.
For more options, visit https://groups.google.com/d/optout 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/7AEDDBDE-2B9D-4660-8792-8257DF0EEC19%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.