# CustomScoreQueryBuilder param values unexpectedly cast to java.lang.String

**URL:** <https://discuss.elastic.co/t/customscorequerybuilder-param-values-unexpectedly-cast-to-java-lang-string/5741>\
**Category:** Elasticsearch\
**Created:** [November 1, 2011, 10:15pm UTC](https://discuss.elastic.co/t/customscorequerybuilder-param-values-unexpectedly-cast-to-java-lang-string/5741 "2011-11-01T22:15:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_2](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Alex\_2](https://discuss.elastic.co/u/Alex_2)\
**Post date:** [November 1, 2011, 10:15pm UTC](https://discuss.elastic.co/t/customscorequerybuilder-param-values-unexpectedly-cast-to-java-lang-string/5741/1 "2011-11-01T22:15:38Z")

</div>

The parameter values added to a CustomScoreQueryBuilder by  
using .param(java.lang.String key, java.lang.Object value) end up being  
Strings when retrieved in an implementation of, for example,  
AbstractDoubleSearchScript. Somewhere the values are cast to  
java.lang.String, but I couldn't find where. Is this behavior expected?

Cheers  
Alex

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 1, 2011, 11:01pm UTC](https://discuss.elastic.co/t/customscorequerybuilder-param-values-unexpectedly-cast-to-java-lang-string/5741/2 "2011-11-01T23:01:01Z")

</div>

No, it should maintain its native type (i.e. Double, or Integer). Can you  
open an issue, I will have a look...

On Wed, Nov 2, 2011 at 12:15 AM, Alex  
[alessandro.usseglioviretta@gmail.com](mailto:alessandro.usseglioviretta@gmail.com)wrote:

> The parameter values added to a CustomScoreQueryBuilder by  
> using .param(java.lang.String key, java.lang.Object value) end up being  
> Strings when retrieved in an implementation of, for example,  
> AbstractDoubleSearchScript. Somewhere the values are cast to  
> java.lang.String, but I couldn't find where. Is this behavior expected?
> 
> Cheers  
> Alex

---

<div class="post-metadata">

**Author:** ![Alex\_2](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Alex\_2](https://discuss.elastic.co/u/Alex_2)\
**Post date:** [November 1, 2011, 11:59pm UTC](https://discuss.elastic.co/t/customscorequerybuilder-param-values-unexpectedly-cast-to-java-lang-string/5741/3 "2011-11-01T23:59:46Z")

</div>

alright, this is the Scala code to replicate the problem

> <https://gist.github.com/anonymous/1332314>

  
and here is the stack trace  

> <https://gist.github.com/anonymous/1332314>

Cheers  
Alex

---

<div class="post-metadata">

**Author:** ![Alex\_2](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Alex\_2](https://discuss.elastic.co/u/Alex_2)\
**Post date:** [November 2, 2011, 12:03am UTC](https://discuss.elastic.co/t/customscorequerybuilder-param-values-unexpectedly-cast-to-java-lang-string/5741/4 "2011-11-02T00:03:27Z")

</div>

Double and Int work as expected. Are there limitations in the types that  
can be used?

Alex

---

<div class="post-metadata">

**Author:** ![Alex\_2](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Alex\_2](https://discuss.elastic.co/u/Alex_2)\
**Post date:** [November 2, 2011, 1:31am UTC](https://discuss.elastic.co/t/customscorequerybuilder-param-values-unexpectedly-cast-to-java-lang-string/5741/5 "2011-11-02T01:31:38Z")

</div>

A hint that might help solve the riddle: if the value placed into the param  
is a java.util.HashMap instead of Test,  
that is .param("test", someHashMap\<String, Test\>)), it works as expected.

Alex

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 2, 2011, 6:33pm UTC](https://discuss.elastic.co/t/customscorequerybuilder-param-values-unexpectedly-cast-to-java-lang-string/5741/6 "2011-11-02T18:33:22Z")

</div>

The parameters supported are only the ones supported by "json", i.e. native  
types (numeric, string), and map/lists. Are you trying to pass a "custom"  
class? In this case, it will just pass the "toString" representation of it.

On Wed, Nov 2, 2011 at 3:31 AM, Alex  
[alessandro.usseglioviretta@gmail.com](mailto:alessandro.usseglioviretta@gmail.com)wrote:

> A hint that might help solve the riddle: if the value placed into the  
> param is a java.util.HashMap instead of Test,  
> that is .param("test", someHashMap\<String, Test\>)), it works as expected.
> 
> Alex

---

<div class="post-metadata">

**Author:** ![Alex\_2](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Alex\_2](https://discuss.elastic.co/u/Alex_2)\
**Post date:** [November 2, 2011, 7:04pm UTC](https://discuss.elastic.co/t/customscorequerybuilder-param-values-unexpectedly-cast-to-java-lang-string/5741/7 "2011-11-02T19:04:40Z")

</div>

ok, that makes sense. Thanks!

Alex

---

<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, 3:50am UTC](https://discuss.elastic.co/t/customscorequerybuilder-param-values-unexpectedly-cast-to-java-lang-string/5741/8 "2017-07-06T03:50:04Z")

</div>


