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

**URL:** <https://discuss.elastic.co/t/pre-registered-templates-java-api-passing-collection-to-param/21707>\
**Category:** Elasticsearch\
**Created:** [January 19, 2015, 8:54am UTC](https://discuss.elastic.co/t/pre-registered-templates-java-api-passing-collection-to-param/21707 "2015-01-19T08:54:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_Kubina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafael_kubina/32/83691_2.png) [@Rafael\_Kubina](https://discuss.elastic.co/u/Rafael_Kubina)\
**Post date:** [January 19, 2015, 8:54am UTC](https://discuss.elastic.co/t/pre-registered-templates-java-api-passing-collection-to-param/21707/1 "2015-01-19T08:54:57Z")

</div>

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 🙂  
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](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).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 19, 2015, 9:03am UTC](https://discuss.elastic.co/t/pre-registered-templates-java-api-passing-collection-to-param/21707/2 "2015-01-19T09:03:29Z")

</div>

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) [https://github.com/elasticsearch/elasticsearch/commit/fda1576d55fdd56fd44df6d4608dca74d33d1536](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) [https://github.com/elasticsearch/elasticsearch/commit/350a2db8dfcaee134f85c8d8419970812a49ea2c](https://github.com/elasticsearch/elasticsearch/commit/350a2db8dfcaee134f85c8d8419970812a49ea2c)

So it will be available in 1.5.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)

> Le 19 janv. 2015 à 09:54, Rafael Kubina [rafael.kubina@gmail.com](mailto: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 🙂  
> 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](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) [mailto: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) [https://groups.google.com/d/msgid/elasticsearch/99aac531-20e7-44c5-821f-e04b4f7b9f38%40googlegroups.com?utm\_medium=email&utm\_source=footer](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) [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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/7AEDDBDE-2B9D-4660-8792-8257DF0EEC19%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:38am UTC](https://discuss.elastic.co/t/pre-registered-templates-java-api-passing-collection-to-param/21707/3 "2017-07-06T00:38:06Z")

</div>


