How can i add a field with 2.3.3?

the demo document:
curl -XPUT http://localhost:9200/blog/article/1 -d '{"title": "New version of Elasticsearch released!", "content": "Version 1.0 released today!", "tags": ["announce","elasticsearch", "release"]}'

then i want add a field:
curl -XPOST http://localhost:9200/blog/article/1/_update -d '{"script": "ctx._source.counter += 1","upsert": {"counter" : 0}}'

I get the msg:

{
"error": {
"root_cause": [
{
"type": "remote_transport_exception",
"reason": "[Delphine Courtney][127.0.0.1:9300][indices:data/write/update[s]]"
}
],
"type": "illegal_argument_exception",
"reason": "failed to execute script",
"caused_by": {
"type": "script_exception",
"reason": "failed to run inline script [ctx._source.counter += 1] using lang [groovy]",
"caused_by": {
"type": "null_pointer_exception",
"reason": "Cannot execute null+1"
}
}
},
"status": 400
}

my config file content:
script.inline: on script.indexed: on script.engine.groovy.inline.aggs: on script.engine.groovy.inline.update: on

i'm a newcomer.
thank you.

You did not set any value for counter in the original document. How could it be incremented?

I resolved,
ctx._source.counter += 1
==》ctx._source.counter = 1

thank you!

But why do you want to use a script for such an update?

e,i study es.this is a demo from a book.I just step by step according to the book. and at last,i find the book(a chinese editon) is just so so.:joy::joy:

Ok.

Just to make sure you understand, if you want to send a new version of a document (update a document that is), you can do:

# This is the first version of the doc
PUT index/type/1
{
  "foo": "bar"
}

# This is the new version of the doc
PUT index/type/1
{
  "foo": "baz"
}

You don't need to run a script for that.

get,update the value of field.
thanks.