Match_all & update_by_query & script error!

# running ok
    POST products/_update_by_query
    {
      "script": {
        "source": "ctx._source.in_stock++",
        "lang": "painless"
      },
      "query": {
        "term": {
          "name": "LED TV"
        }
      }
    }
# running ok
    POST products/_search
    {
      "query": {
          "match_all": {}
      }
    }
# running error
    POST products/_update_by_query
    {
      "script": {
        "source": "ctx._source.in_stock++",
        "lang": "painless"
      },
      "query": {
          "match_all": {}
      }
    }

The errors as below:

{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source.in_stock++",
"^---- HERE"
],
"script": "ctx._source.in_stock++",
"lang": "painless"
}
],
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source.in_stock++",
"^---- HERE"
],
"script": "ctx._source.in_stock++",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
},
"status": 400
}

may be some of the field in_stock is value nill ?

1 Like
# running ok
    POST products/_update_by_query
    {
      "script": {
        "source": "ctx._source.in_stock++",
        "lang": "painless"
      },
      "query": {
            "exists": {
            "field": "in_stock"
          }
      }
    }

Yes, you are right! thanks!

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