# How to fix array index out of bounds exception on Array field in Aggregation

**URL:** <https://discuss.elastic.co/t/how-to-fix-array-index-out-of-bounds-exception-on-array-field-in-aggregation/159292>\
**Category:** Elasticsearch\
**Created:** [December 4, 2018, 6:20am UTC](https://discuss.elastic.co/t/how-to-fix-array-index-out-of-bounds-exception-on-array-field-in-aggregation/159292 "2018-12-04T06:20:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmminov](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@pmminov](https://discuss.elastic.co/u/pmminov)\
**Post date:** [December 4, 2018, 6:20am UTC](https://discuss.elastic.co/t/how-to-fix-array-index-out-of-bounds-exception-on-array-field-in-aggregation/159292/1 "2018-12-04T06:20:51Z")

</div>

I'm trying to get the values of a multified with my term aggregation and I'm seeing something odd. I have 2 fields, one is an array and the other is just a string. Both have a keyword field to store the keyword version of the value and a 2nd multifield that has a normalized version of it. I want for my buckets to bring both the key and the normalized version

```
"industries": {
      "properties": {
        "name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            },
            "normalized": {
              "type": "keyword",
              "ignore_above": 256,
              "normalizer": "xyz_normalizer"
            }
          }
        }
      }
    },
"representative": {
      "properties": {
        "name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword"
            },
            "normalized": {
              "type": "keyword",
              "ignore_above": 256,
              "normalizer": "xyz_normalizer"
            }
          }
        }
      }
    }

```

I had not much luck with finding a way and resorted to an aggregation term with a script, but this is where it gets strange. The following throws a array\_index\_out\_of\_bounds\_exception

```
{
  "size": 0,
  "aggs": {
    "platforms": {
      "terms": {
        "field": "industries.name.keyword",
        "script": "doc['industries.name.keyword']+ ',' + doc['industries.name.normalized']"
      }
    }
  }
}

```

However if I do it for my other field it works:

```
{
  "size": 0,
  "aggs": {
    "platforms": {
      "terms": {
        "field": "industries.name.keyword",
        "script": "doc['representative.keyword']+ ',' + doc['representative.normalized']"
      }
    }
  }
}

```

How do I make my script capable of working for the array value as it does for the plain one?

---

<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:** [January 1, 2019, 6:20am UTC](https://discuss.elastic.co/t/how-to-fix-array-index-out-of-bounds-exception-on-array-field-in-aggregation/159292/2 "2019-01-01T06:20:53Z")

</div>

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