Painless Access array object

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

"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

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

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

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