# Problem with mvel script on array of geo-points

**URL:** <https://discuss.elastic.co/t/problem-with-mvel-script-on-array-of-geo-points/4896>\
**Category:** Elasticsearch\
**Created:** [July 19, 2011, 2:46pm UTC](https://discuss.elastic.co/t/problem-with-mvel-script-on-array-of-geo-points/4896 "2011-07-19T14:46:30Z")\
**Posts on this page:** 4\
**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 19, 2011, 2:46pm UTC](https://discuss.elastic.co/t/problem-with-mvel-script-on-array-of-geo-points/4896/1 "2011-07-19T14:46:30Z")

</div>

I have a set of documents with an array of geo-points (the mapping is  
enforced). I am trying to run some mvel scripts that generate various  
fields based on the lat/long values in the array.

1] This test case works, I do "i = 0; n = 0; d = 0; if  
(doc['locs'].values.length \> 0) { d = doc['locs'].lons[0]; } d;"

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

2] This trivial change causes it to fail: "i = 0; n = 0; d = 0; if  
(doc['locs'].values.length \> 0) { d = doc['locs'].lons[i]; } d;"

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

(ie I change the index of the lons array to be "i" vs 0; It also fails  
with i declared as int, long, Integer, or Long; or the array index  
being (int)0, (Integer)0, (long)0, (Long)0)

Am I doing something stupid, is this a bug in mvel (eg a change to JS  
will workaround it), or a bug in the ElasticSearch/script interface?

Many thanks, as always, for any insight or help anyone can provide

Alex

---

<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 21, 2011, 4:45pm UTC](https://discuss.elastic.co/t/problem-with-mvel-script-on-array-of-geo-points/4896/2 "2011-07-21T16:45:21Z")

</div>

Update on this (nobody else using mvel? :P)

The following was a workaround:

"i = 0; d = 0; if (doc['locs'].values.length \> 0) { d =  
doc['locs'].values[i].lat; } d;"

ie it looks like there's a bug with the ".lats" and ".lons" shortcuts,  
I'll go file an issue.

On Jul 19, 10:46 am, Alex at Ikanow [apigg...@ikanow.com](mailto:apigg...@ikanow.com) wrote:

> I have a set of documents with an array of geo-points (the mapping is  
> enforced). I am trying to run some mvel scripts that generate various  
> fields based on the lat/long values in the array.
> 
> 1] This test case works, I do "i = 0; n = 0; d = 0; if  
> (doc['locs'].values.length \> 0) { d = doc['locs'].lons[0]; } d;"
> 
> [Working mvel/geopoint array · GitHub](https://gist.github.com/1092577)
> 
> 2] This trivial change causes it to fail: "i = 0; n = 0; d = 0; if  
> (doc['locs'].values.length \> 0) { d = doc['locs'].lons[i]; } d;"
> 
> [Failing mvel/geopoint array · GitHub](https://gist.github.com/1092581)
> 
> (ie I change the index of the lons array to be "i" vs 0; It also fails  
> with i declared as int, long, Integer, or Long; or the array index  
> being (int)0, (Integer)0, (long)0, (Long)0)
> 
> Am I doing something stupid, is this a bug in mvel (eg a change to JS  
> will workaround it), or a bug in the Elasticsearch/script interface?
> 
> Many thanks, as always, for any insight or help anyone can provide
> 
> Alex

---

<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:40pm UTC](https://discuss.elastic.co/t/problem-with-mvel-script-on-array-of-geo-points/4896/3 "2011-07-22T20:40:34Z")

</div>

One "final" update:

- In "mvel", "values" fails for me when the array has size 1 (https://  
[Scripts: arrays: ".multiValued" returns true even when ".values" fails · Issue #1145 · elastic/elasticsearch · GitHub](http://github.com/elasticsearch/elasticsearch/issues/1145))
- In "js", "values" always fails for me, but "lats" and "lons" both  
work (for all array sizes)

On Jul 21, 12:45 pm, Alex at Ikanow [apigg...@ikanow.com](mailto:apigg...@ikanow.com) wrote:

> Update on this (nobody else using mvel? :P)
> 
> The following was a workaround:
> 
> "i = 0; d = 0; if (doc['locs'].values.length \> 0) { d =  
> doc['locs'].values[i].lat; } d;"
> 
> ie it looks like there's a bug with the ".lats" and ".lons" shortcuts,  
> I'll go file an issue.
> 
> On Jul 19, 10:46 am, Alex at Ikanow [apigg...@ikanow.com](mailto:apigg...@ikanow.com) wrote:
> 
> > I have a set of documents with an array of geo-points (the mapping is  
> > enforced). I am trying to run some mvel scripts that generate various  
> > fields based on the lat/long values in the array.
> 
> > 1] This test case works, I do "i = 0; n = 0; d = 0; if  
> > (doc['locs'].values.length \> 0) { d = doc['locs'].lons[0]; } d;"
> 
> > [Working mvel/geopoint array · GitHub](https://gist.github.com/1092577)
> 
> > 2] This trivial change causes it to fail: "i = 0; n = 0; d = 0; if  
> > (doc['locs'].values.length \> 0) { d = doc['locs'].lons[i]; } d;"
> 
> > [Failing mvel/geopoint array · GitHub](https://gist.github.com/1092581)
> 
> > (ie I change the index of the lons array to be "i" vs 0; It also fails  
> > with i declared as int, long, Integer, or Long; or the array index  
> > being (int)0, (Integer)0, (long)0, (Long)0)
> 
> > Am I doing something stupid, is this a bug in mvel (eg a change to JS  
> > will workaround it), or a bug in the Elasticsearch/script interface?
> 
> > Many thanks, as always, for any insight or help anyone can provide
> 
> > 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:59am UTC](https://discuss.elastic.co/t/problem-with-mvel-script-on-array-of-geo-points/4896/4 "2017-07-06T03:59:45Z")

</div>


