# Painless Access array object

**URL:** <https://discuss.elastic.co/t/painless-access-array-object/281253>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [August 12, 2021, 7:28pm UTC](https://discuss.elastic.co/t/painless-access-array-object/281253 "2021-08-12T19:28:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aaish\_Sindwani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaish_sindwani/32/77345_2.png) [@Aaish\_Sindwani](https://discuss.elastic.co/u/Aaish_Sindwani)\
**Post date:** [August 12, 2021, 7:28pm UTC](https://discuss.elastic.co/t/painless-access-array-object/281253/1 "2021-08-12T19:28:28Z")

</div>

HI Team,

I am trying to access an array object within the source in the painless script but I am not able to with the error

```auto
"failed_shards" : [
      {
        "shard" : 0,
        "index" : "boxIndex",
        "node" : "gsbkERMmT72w3IV4SwuIDw",
        "reason" : {
          "type" : "script_exception",
          "reason" : "runtime error",
          "script_stack" : [
            "if (params._source.boxArray[0].boxName =="red"){\n ",
            " ^---- HERE"
          ],
          "script" : " ...",
          "lang" : "painless",
          "position" : {
            "offset" : 41,
            "start" : 23,
            "end" : 105
          },
          "caused_by" : {
            "type" : "null_pointer_exception",
            "reason" : "Cannot invoke \"Object.getClass()\" because \"callArgs[0]\" is null"
          }
        }
      }
    ]

```

My Request is

```auto
GET /boxIndex/_search
{
   "query":{
      "bool":{
         "must":{
            "script":{
               "script":{
                  "lang":"painless",
                  "source": """
                      if (params._source.boxArray[0].boxName == "red"){
                        return true;
                      }
return false;
                """
               }
            }
         }
      }
   }
}

```

The Object is stored as

````auto
"_source": {
	"boxArray": [{
		"boxName": "red"
	}]
}```
````

---

<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 9, 2021, 7:29pm UTC](https://discuss.elastic.co/t/painless-access-array-object/281253/2 "2021-09-09T19:29:03Z")

</div>

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