Null pointer exception for finding an integer in an array


(pungent) #1

I have mapping of one filed is as follows in ES2.3

"move_in_ts": {
  "type": "integer"
}

Sample document stores data as follows:

"move_in_ts": [
        1475280000,
        1475539200,
        1475712000,
        1475884800,
        1477008000,
        1477785600
      ]

I have a script in my DSL query (trying to find an integer in that array)

"script": "if(doc['move_in_ts'] && doc['move_in_ts'].values.contains('1475280000')){return 200;}"

and also tried this:

 "script": "if(doc['move_in_ts'] && doc['move_in_ts'].contains('1475280000')){return 200;}"

and also tried this:

 "script": "if(doc['move_in_ts'] && doc['move_in_ts'].contains(1475280000)){return 200;}"

and also tried this:

 "script": "if(doc['move_in_ts'] && doc['move_in_ts'].values.contains(1475280000)){return 200;}"

but in above cases, I get the following error:

"reason": {
      "type": "null_pointer_exception",
      "reason": null
    }

It might be possible that this field doesn't exist at all in few documents (I cannot use filter in my use case, I need to have it in the script only)

What am I doing wrong or how to get it work?


(system) #2