Scripting issue with arrays that can have size 1


(Alex Piggott) #1

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!

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.

(Alex Piggott) #2

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 :frowning:

The bug is real though....

On Jul 22, 3:57 pm, Alex at Ikanow 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!

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.

(system) #3