# Arrays indexes starts at -1 with painless on Kibana v7.4.0

**URL:** <https://discuss.elastic.co/t/arrays-indexes-starts-at-1-with-painless-on-kibana-v7-4-0/203427>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [October 14, 2019, 10:05am UTC](https://discuss.elastic.co/t/arrays-indexes-starts-at-1-with-painless-on-kibana-v7-4-0/203427 "2019-10-14T10:05:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vb\_everysens](https://avatars.discourse-cdn.com/v4/letter/v/e5b9ba/32.png) [@vb\_everysens](https://discuss.elastic.co/u/vb_everysens)\
**Post date:** [October 14, 2019, 10:05am UTC](https://discuss.elastic.co/t/arrays-indexes-starts-at-1-with-painless-on-kibana-v7-4-0/203427/1 "2019-10-14T10:05:39Z")

</div>

I'm using kibana v7.4.0 deployed via [cloud.elastic.co](http://cloud.elastic.co)

I was trying to create a scripted field to match a specific field with a regex.  
The field I'm working with in an analyzed string field containing a process' arguments :

```
def processArgs = doc['process.args']; 

```

if contans something like :

```
{
  "_id": "DBYUvm0BRrdyTjK0i_EP",
  "process": {
   "args": [
    "/usr/share/metricbeat/bin/metricbeat",
    "-path.home",
    "/usr/share/metricbeat",
    "-path.config",
    "/etc/metricbeat",
    "-path.data",
    "/var/lib/metricbeat",
    "-path.logs",
    "/var/log/metricbeat",
    "run"
   ]
  }
 }

```

However in my script, when I try to access the first value of the array I would normally do :

`doc['process.args'][0]`

Except it doesn't work ! It returns the value of the second element of the array !

After some painful testing, the painless interpreter seems to interpret array indexing as :

```
doc['process.args'][-2] -> last
doc['process.args'][-1] -> 1stelement
doc['process.args'][0] -> 2nd element
doc['process.args'][1] -> 3rd element
doc['process.args'][doc['process.args'].length - 2] -> last element
etc ..

```

And it loops around the (end - 2) index of the array.

What witchery is that ?!

---

<div class="post-metadata">

**Author:** ![ppisljar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppisljar/32/11588_2.png) [@ppisljar](https://discuss.elastic.co/u/ppisljar)\
**Post date:** [October 14, 2019, 11:46am UTC](https://discuss.elastic.co/t/arrays-indexes-starts-at-1-with-painless-on-kibana-v7-4-0/203427/2 "2019-10-14T11:46:27Z")

</div>

could you please open an issue as this is a bug not a question.

> **[Build software better, together](https://github.com/elastic/kibana/issues/new?template=Bug_report.md)**
>
> GitHub is where people build software. More than 40 million people use GitHub to discover, fork, and contribute to over 100 million projects.

thanks

---

<div class="post-metadata">

**Author:** ![vb\_everysens](https://avatars.discourse-cdn.com/v4/letter/v/e5b9ba/32.png) [@vb\_everysens](https://discuss.elastic.co/u/vb_everysens)\
**Post date:** [October 14, 2019, 11:53am UTC](https://discuss.elastic.co/t/arrays-indexes-starts-at-1-with-painless-on-kibana-v7-4-0/203427/3 "2019-10-14T11:53:31Z")

</div>

Ok, here it is : [https://github.com/elastic/kibana/issues/48087](https://github.com/elastic/kibana/issues/48087)

---

<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:** [November 11, 2019, 12:02pm UTC](https://discuss.elastic.co/t/arrays-indexes-starts-at-1-with-painless-on-kibana-v7-4-0/203427/4 "2019-11-11T12:02:08Z")

</div>

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