# Update Index

**URL:** <https://discuss.elastic.co/t/update-index/7449>\
**Category:** Elasticsearch\
**Created:** [April 24, 2012, 11:26am UTC](https://discuss.elastic.co/t/update-index/7449 "2012-04-24T11:26:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andavar](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@andavar](https://discuss.elastic.co/u/andavar)\
**Post date:** [April 24, 2012, 11:26am UTC](https://discuss.elastic.co/t/update-index/7449/1 "2012-04-24T11:26:31Z")

</div>

Dear Elastic Search User,

```
I come to know there is an <b>UpdateRequest is availble in ES version0.19.0</b>, and i can use it like 

```

UpdateRequest updateRequest = new UpdateRequest(indexName,indexType,indexId);  
**client.update(updateRequest);**  
and I am not sure how to pass the updated source to do updateIndex.

so far I am doing update index by the below steps in **ES version 0.18.7** by

1. GetRequest getRequest = new GetRequest(indexName,indexType, indexId);
2. GetResponse response = client.get(getRequest).get();  
//document already existing in the elastic search engine  
3 .Map\<String, Object\> responseSourceMap = response.getSource();
3. responseSourceMap .put(document to update);
4. create a indexrequest with source as responseSourceMap
5. client.index(indexRequest);

I have a question of what is the **advantage** of using **client.update(updateRequest)** instead of **client.index(indexRequest)** and **how to use properly client.update(updateRequest)**?  
Please share your thoughts.

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 24, 2012, 1:56pm UTC](https://discuss.elastic.co/t/update-index/7449/2 "2012-04-24T13:56:17Z")

</div>

Update API allows you to change records on the server using a script  
without need to pull a record to the client, modify it and send it back to  
the server. Update API also uses versioning to ensure update consistency.  
So, in your examples operations 1-6 are done on the server including  
operation 4 that is specified as a script and runs on the elasticsearch  
server as well. See documentation  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html) and  
discussion here [Update API: Allow to update a document based on a script · Issue #1583 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1583)  
for more information.

On Tuesday, April 24, 2012 7:26:32 AM UTC-4, Periyandavar wrote:

> Dear Elastic Search User,
> 
> ```
> I come to know there is an *UpdateRequest is availble in ES
> 
> ```
> 
> version0.19.0\*, and i can use it like  
> UpdateRequest updateRequest = new  
> UpdateRequest(indexName,indexType,indexId);  
> _client.update(updateRequest);_  
> and I am not sure how to pass the updated source to do updateIndex.
> 
> so far I am doing update index by the below steps in\* ES version 0.18.7\* by
> 
> 1. GetRequest getRequest = new GetRequest(indexName,indexType, indexId);
> 2. GetResponse response = client.get(getRequest).get();  
> //document already existing in the Elasticsearch engine  
> 3 .Map\<String, Object\> responseSourceMap = response.getSource();
> 3. responseSourceMap .put(document to update);
> 4. create a indexrequest with source as responseSourceMap
> 5. client.index(indexRequest);
> 
> I have a question of what is the _advantage_ of using  
> _client.update(updateRequest)_ instead of _client.index(indexRequest)_ and  
> _how to use properly client.update(updateRequest)_?  
> Please share your thoughts.
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Update-Index-tp3935060p3935060.html](http://elasticsearch-users.115913.n3.nabble.com/Update-Index-tp3935060p3935060.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![andavar](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@andavar](https://discuss.elastic.co/u/andavar)\
**Post date:** [April 24, 2012, 3:12pm UTC](https://discuss.elastic.co/t/update-index/7449/3 "2012-04-24T15:12:51Z")

</div>

Thank you very much Igor Motov..

---

<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:31am UTC](https://discuss.elastic.co/t/update-index/7449/4 "2017-07-06T03:31:14Z")

</div>


