# Scripting issue with arrays that can have size 1

**URL:** <https://discuss.elastic.co/t/scripting-issue-with-arrays-that-can-have-size-1/4929>\
**Category:** Elasticsearch\
**Created:** [July 22, 2011, 7:57pm UTC](https://discuss.elastic.co/t/scripting-issue-with-arrays-that-can-have-size-1/4929 "2011-07-22T19:57:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_At\_Ikanow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_at_ikanow/32/676_2.png) [@Alex\_At\_Ikanow](https://discuss.elastic.co/u/Alex_At_Ikanow)\
**Post date:** [July 22, 2011, 7:57pm UTC](https://discuss.elastic.co/t/scripting-issue-with-arrays-that-can-have-size-1/4929/1 "2011-07-22T19:57:20Z")

</div>

I created an issue for this and wasn't going to bother the discussion  
board, but since I found a workaround I thought I'd mention it here  
for the benefit of Google-searchers. Shay, if you don't think it needs  
to be in both places, feel free to delete in one of them!

> <https://github.com/elastic/elasticsearch/issues/1145>

Summary:

In "js" and "mvel", 0.16.2:

1] If you try to treat a single value as an array using  
"doc['field'].values", you get an exception (which is annoying because  
it includes arrays of size 1, where as a script writer you'd obviously  
like to have a single clause to handle all arrays)

2] More importantly, "doc['field'].multiValued" returns true in both  
cases, so you cannot distinguish between arrays of size 1 and size \>

1. For mvel I can't see a workaround. For javascript use "doc['field']  
== Array" instead.

---

<div class="post-metadata">

**Author:** ![Alex\_At\_Ikanow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_at_ikanow/32/676_2.png) [@Alex\_At\_Ikanow](https://discuss.elastic.co/u/Alex_At_Ikanow)\
**Post date:** [July 22, 2011, 8:09pm UTC](https://discuss.elastic.co/t/scripting-issue-with-arrays-that-can-have-size-1/4929/2 "2011-07-22T20:09:18Z")

</div>

Sorry all, I let my optimism get the better of me. The "workaround"  
stops it from throwing an exception but only because it always returns  
false ☹

The bug is real though....

On Jul 22, 3:57 pm, Alex at Ikanow [apigg...@ikanow.com](mailto:apigg...@ikanow.com) wrote:

> I created an issue for this and wasn't going to bother the discussion  
> board, but since I found a workaround I thought I'd mention it here  
> for the benefit of Google-searchers. Shay, if you don't think it needs  
> to be in both places, feel free to delete in one of them!
> 
> [Scripts: arrays: ".multiValued" returns true even when ".values" fails · Issue #1145 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1145)
> 
> Summary:
> 
> In "js" and "mvel", 0.16.2:
> 
> 1] If you try to treat a single value as an array using  
> "doc['field'].values", you get an exception (which is annoying because  
> it includes arrays of size 1, where as a script writer you'd obviously  
> like to have a single clause to handle all arrays)
> 
> 2] More importantly, "doc['field'].multiValued" returns true in both  
> cases, so you cannot distinguish between arrays of size 1 and size \>
> 
> 1. For mvel I can't see a workaround. For javascript use "doc['field']  
> == Array" instead.

---

<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:59am UTC](https://discuss.elastic.co/t/scripting-issue-with-arrays-that-can-have-size-1/4929/3 "2017-07-06T03:59:46Z")

</div>


