# When adding a script\_field to a result, it results in not being able to compile

**URL:** <https://discuss.elastic.co/t/when-adding-a-script-field-to-a-result-it-results-in-not-being-able-to-compile/247119>\
**Category:** Elasticsearch\
**Created:** [September 1, 2020, 3:31pm UTC](https://discuss.elastic.co/t/when-adding-a-script-field-to-a-result-it-results-in-not-being-able-to-compile/247119 "2020-09-01T15:31:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![meadows.120](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@meadows.120](https://discuss.elastic.co/u/meadows.120)\
**Post date:** [September 1, 2020, 3:31pm UTC](https://discuss.elastic.co/t/when-adding-a-script-field-to-a-result-it-results-in-not-being-able-to-compile/247119/1 "2020-09-01T15:31:19Z")

</div>

ES Version: 7.8

I am trying to use the following to check if a value is present in an array of strings, but I get a runtime error every time:

```auto
{
  "script": {
    "source": "doc['mediaDetails.tags'].values.contains('Highlight')"
}

```

---

<div class="post-metadata">

**Author:** ![meadows.120](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@meadows.120](https://discuss.elastic.co/u/meadows.120)\
**Post date:** [September 1, 2020, 4:39pm UTC](https://discuss.elastic.co/t/when-adding-a-script-field-to-a-result-it-results-in-not-being-able-to-compile/247119/2 "2020-09-01T16:39:02Z")

</div>

Now I get the following when trying other access methods:

```json
{
  "took" : 8,
  "timed_out" : false,
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 1,
    "failures" : [
      {
        "shard" : 0,
        "index" : "videos_eric_meadows",
        "node" : "T453XWINT3mqBPradGk4zQ",
        "reason" : {
          "type" : "script_exception",
          "reason" : "runtime error",
          "script_stack" : [
            "params['_source']['mediaDetails']['primaryTags'].length",
            " ^---- HERE"
          ],
          "script" : "params['_source']['mediaDetails']['primaryTags'].length",
          "lang" : "painless",
          "position" : {
            "offset" : 48,
            "start" : 0,
            "end" : 55
          },
          "caused_by" : {
            "type" : "null_pointer_exception",
            "reason" : "Cannot invoke \"Object.getClass()\" because \"callArgs[0]\" is null"
          }
        }
      }
    ]
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : 1.0,
    "hits" : []
  }
}

```

---

<div class="post-metadata">

**Author:** ![meadows.120](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@meadows.120](https://discuss.elastic.co/u/meadows.120)\
**Post date:** [September 2, 2020, 2:23pm UTC](https://discuss.elastic.co/t/when-adding-a-script-field-to-a-result-it-results-in-not-being-able-to-compile/247119/3 "2020-09-02T14:23:43Z")

</div>

Solved by fixing the field type. The field type was set to int, but when I added in a string, it converted it to text.

---

<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:** [September 30, 2020, 2:23pm UTC](https://discuss.elastic.co/t/when-adding-a-script-field-to-a-result-it-results-in-not-being-able-to-compile/247119/4 "2020-09-30T14:23:44Z")

</div>

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