# Document update

**URL:** <https://discuss.elastic.co/t/document-update/6655>\
**Category:** Elasticsearch\
**Created:** [February 9, 2012, 11:05am UTC](https://discuss.elastic.co/t/document-update/6655 "2012-02-09T11:05:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)\
**Post date:** [February 9, 2012, 11:05am UTC](https://discuss.elastic.co/t/document-update/6655/1 "2012-02-09T11:05:55Z")

</div>

Hi there,

```
            I want to know if there is any provision to update the 

```

document?? I am currently handling this by getting the document and then  
altering and re-indexing the same document. Can i direclty update the field  
or insert some field in the already existing document without pull and push  
of the document to the index????

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [February 9, 2012, 1:11pm UTC](https://discuss.elastic.co/t/document-update/6655/2 "2012-02-09T13:11:22Z")

</div>

Hi,

have a look at new Update API (available from 0.19.0.RC1).

> <https://github.com/elastic/elasticsearch/issues/1583>
>
> The update action allows to directly update a specific document based on a scrip…t. The operation gets the document (collocated with the shard) from the index, runs the script (with optional script language and parameters), and index back the result (also allows to delete, or ignore the operation). 
> 
> Note, this operation still means full reindex of the document, it just removes some network roundtrips and reduces chances of version conflicts between the get and the index.
> 
> For example, lets index a simple doc:
> 
> \`\`\`
> curl -XPUT localhost:9200/test/type1/1 -d '{
> "counter" : 1,
> "tags" : \["red"\]
> }'
> \`\`\`
> 
> Now, we can execute a script that would increment the counter
> 
> \`\`\`
> curl -XPOST 'localhost:9200/test/type1/1/\_update' -d '{
> "script" : "ctx.\_source.counter += count",
> "params" : {
> "count" : 4
> }
> }'
> \`\`\`
> 
> We can also add a tag to the list of tags:
> 
> \`\`\`
> curl -XPOST 'localhost:9200/test/type1/1/\_update' -d '{
> "script" : "ctx.\_source.tags += tag",
> "params" : {
> "tag" : "blue"
> }
> }'
> \`\`\`
> 
> And, we can delete the doc if the tags contain \`blue\`, or ignore (noop):
> 
> \`\`\`
> curl -XPOST 'localhost:9200/test/type1/1/\_update' -d '{
> "script" : "ctx.\_source.tags.contains(tag) ? ctx.op = \\"delete\\" : ctx.op = \\"none\\"",
> "params" : {
> "tag" : "blue"
> }
> }'
> \`\`\`
> \## Parameters:
> \- \`routing\`: Sets the routing that will be used to route the document to the relevant shard.
> \- \`parent\`: Simply sets the routing.
> \- \`timeout\`: Timeout waiting for a shard to become available.
> \- \`replication\`: The replication type for the delete/index operation (\`sync\` or \`async\`).
> \- \`consistency\`: The write consistency of the index/delete operation.
> \- \`retry\_on\_conflict\`: How many times to retry if there is a version conflict between getting the document and indexing / deleting it. Defaults to \`0\`.

Regards,  
Lukas

On Thu, Feb 9, 2012 at 12:05 PM, Narinder Kaur [narinder.kaur@izap.in](mailto:narinder.kaur@izap.in)wrote:

> Hi there,
> 
> ```
> I want to know if there is any provision to update the
> 
> ```
> 
> document?? I am currently handling this by getting the document and then  
> altering and re-indexing the same document. Can i direclty update the field  
> or insert some field in the already existing document without pull and push  
> of the document to the index????

---

<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 6, 2017, 3:39am UTC](https://discuss.elastic.co/t/document-update/6655/3 "2017-07-06T03:39:58Z")

</div>


