# How can i add a field with 2.3.3?

**URL:** <https://discuss.elastic.co/t/how-can-i-add-a-field-with-2-3-3/53117>\
**Category:** Elasticsearch\
**Created:** [June 17, 2016, 8:12am UTC](https://discuss.elastic.co/t/how-can-i-add-a-field-with-2-3-3/53117 "2016-06-17T08:12:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yang\_Long](https://avatars.discourse-cdn.com/v4/letter/y/c67d28/32.png) [@Yang\_Long](https://discuss.elastic.co/u/Yang_Long)\
**Post date:** [June 17, 2016, 8:12am UTC](https://discuss.elastic.co/t/how-can-i-add-a-field-with-2-3-3/53117/1 "2016-06-17T08:12:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 17, 2016, 9:06am UTC](https://discuss.elastic.co/t/how-can-i-add-a-field-with-2-3-3/53117/2 "2016-06-17T09:06:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Yang\_Long](https://avatars.discourse-cdn.com/v4/letter/y/c67d28/32.png) [@Yang\_Long](https://discuss.elastic.co/u/Yang_Long)\
**Post date:** [June 17, 2016, 10:01am UTC](https://discuss.elastic.co/t/how-can-i-add-a-field-with-2-3-3/53117/3 "2016-06-17T10:01:52Z")

</div>

I resolved，  
ctx.\_source.counter += 1  
==》ctx.\_source.counter = 1

thank you!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 17, 2016, 10:47am UTC](https://discuss.elastic.co/t/how-can-i-add-a-field-with-2-3-3/53117/4 "2016-06-17T10:47:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Yang\_Long](https://avatars.discourse-cdn.com/v4/letter/y/c67d28/32.png) [@Yang\_Long](https://discuss.elastic.co/u/Yang_Long)\
**Post date:** [June 24, 2016, 7:16am UTC](https://discuss.elastic.co/t/how-can-i-add-a-field-with-2-3-3/53117/5 "2016-06-24T07:16:00Z")

</div>

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.😂😂

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 24, 2016, 7:29am UTC](https://discuss.elastic.co/t/how-can-i-add-a-field-with-2-3-3/53117/6 "2016-06-24T07:29:16Z")

</div>

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:

```auto
# 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.

---

<div class="post-metadata">

**Author:** ![Yang\_Long](https://avatars.discourse-cdn.com/v4/letter/y/c67d28/32.png) [@Yang\_Long](https://discuss.elastic.co/u/Yang_Long)\
**Post date:** [June 24, 2016, 7:31am UTC](https://discuss.elastic.co/t/how-can-i-add-a-field-with-2-3-3/53117/7 "2016-06-24T07:31:47Z")

</div>

get,update the value of field.  
thanks.

---

<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:** [July 5, 2017, 10:40pm UTC](https://discuss.elastic.co/t/how-can-i-add-a-field-with-2-3-3/53117/8 "2017-07-05T22:40:50Z")

</div>


