# Accessing Arrays inside ElasticSearch Script with Painless

**URL:** <https://discuss.elastic.co/t/accessing-arrays-inside-elasticsearch-script-with-painless/263894>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [February 10, 2021, 3:46pm UTC](https://discuss.elastic.co/t/accessing-arrays-inside-elasticsearch-script-with-painless/263894 "2021-02-10T15:46:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cyphy](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Cyphy](https://discuss.elastic.co/u/Cyphy)\
**Post date:** [February 10, 2021, 3:46pm UTC](https://discuss.elastic.co/t/accessing-arrays-inside-elasticsearch-script-with-painless/263894/1 "2021-02-10T15:46:36Z")

</div>

Hello there,

actually i am trying to compare bounding boxes and score them. For that i am using a painless script which helps me with the math. Unfortunately in some cases my documents doesn't contain only one coordinate for a bounding box side. So it is saved as

```auto
"BB_North" : [
            54.5,
            53.964153
          ],

```

Not really a problem if i would know how to access the indexes or even if that isn't the case, elastic search would serve me everytime the last coordinate. Both isn't really the case XD. So first i don't really know how to acces a specific index of the array (doc['BB\_North'].value only gives one coordinate). And second, because doc['BB\_North'].value obviously gives me a coordinate it is not everytime the same coordinate of the same Place. So in my case Elastic search gives me everytime the last coordinate except for the South coordinate. There Elastic search returns the first one. And i don't even know why he is doing this :D.  
I maybe could use a little help here XD.

Is there a way to acces a specific index of the array, or maybe the hole array to iterate through it?

That's it,  
Cheers.

Oh and sorry for the mistakes, i am not a native english speaker.

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [February 11, 2021, 1:05pm UTC](https://discuss.elastic.co/t/accessing-arrays-inside-elasticsearch-script-with-painless/263894/2 "2021-02-11T13:05:30Z")

</div>

What is your mapping for field `BB_North`?

---

<div class="post-metadata">

**Author:** ![Cyphy](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Cyphy](https://discuss.elastic.co/u/Cyphy)\
**Post date:** [February 25, 2021, 8:46am UTC](https://discuss.elastic.co/t/accessing-arrays-inside-elasticsearch-script-with-painless/263894/3 "2021-02-25T08:46:11Z")

</div>

Sorry, i already bypass the problem by only accessing the first Element of the XML.  
My mapping now looks like:

```auto
xpath => ["//identificationInfo/*/*/*/EX_Extent/geographicElement[1]/EX_GeographicBoundingBox/northBoundLatitude/Decimal/text()", "BB_North"]

```

But another question of a problem that lately occured:  
Sometimes the EX\_Extend keyword isn't three nodes ( /_/_/\* ) after identificatioInfo. Sometimes the keyword is only two nodes after the first node. Is there a way to ask if the mapping was correct? I tried already something like

```auto
if ["BB_North"] {} else{}

```

But it didn't seem to work properly. I alway get either the mapping with 3 nodes or the mapping with 2 nodes. But not both.

---

<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:** [March 25, 2021, 8:46am UTC](https://discuss.elastic.co/t/accessing-arrays-inside-elasticsearch-script-with-painless/263894/4 "2021-03-25T08:46:52Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
