# Updating a document using Java API

**URL:** <https://discuss.elastic.co/t/updating-a-document-using-java-api/18165>\
**Category:** Elasticsearch\
**Created:** [June 17, 2014, 6:23pm UTC](https://discuss.elastic.co/t/updating-a-document-using-java-api/18165 "2014-06-17T18:23:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neera\_Vats](https://avatars.discourse-cdn.com/v4/letter/n/9fc29f/32.png) [@Neera\_Vats](https://discuss.elastic.co/u/Neera_Vats)\
**Post date:** [June 17, 2014, 6:23pm UTC](https://discuss.elastic.co/t/updating-a-document-using-java-api/18165/1 "2014-06-17T18:23:59Z")

</div>

Hi All,

As part of an update request, I need to add new fields to a document(search  
to get the doc-id and then update).

With Lucene API's it can be achieved by 1) reading the doc into a temp  
document 2) update the temp document 3) delete the original document from  
index and add the temp document.

How does update work in ES. It is also delete and add a new document?

My index has some un-stored fields. Is there a way to keep the un-stored  
field after the update or they are lost in ElasticSearch?

Would appreciate any pointers you might have.

Thanks!

Neera

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/22b1bbd3-ce0b-49bf-9eb0-5e1b56edf159%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/22b1bbd3-ce0b-49bf-9eb0-5e1b56edf159%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [June 18, 2014, 5:35pm UTC](https://discuss.elastic.co/t/updating-a-document-using-java-api/18165/2 "2014-06-18T17:35:59Z")

</div>

Are you storing the document source? If so, you can use the update API. If  
not, you would need to reindex from the original source.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--  
Ivan

On Tue, Jun 17, 2014 at 11:23 AM, ESUser [neeravats@gmail.com](mailto:neeravats@gmail.com) wrote:

> Hi All,
> 
> As part of an update request, I need to add new fields to a  
> document(search to get the doc-id and then update).
> 
> With Lucene API's it can be achieved by 1) reading the doc into a temp  
> document 2) update the temp document 3) delete the original document from  
> index and add the temp document.
> 
> How does update work in ES. It is also delete and add a new document?
> 
> My index has some un-stored fields. Is there a way to keep the un-stored  
> field after the update or they are lost in Elasticsearch?
> 
> Would appreciate any pointers you might have.
> 
> Thanks!
> 
> Neera
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/22b1bbd3-ce0b-49bf-9eb0-5e1b56edf159%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/22b1bbd3-ce0b-49bf-9eb0-5e1b56edf159%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/22b1bbd3-ce0b-49bf-9eb0-5e1b56edf159%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/22b1bbd3-ce0b-49bf-9eb0-5e1b56edf159%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAvNUt--knLV9f-yLV9JRuxxz7rgSiD\_cygBZZzoEnptg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAvNUt--knLV9f-yLV9JRuxxz7rgSiD_cygBZZzoEnptg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:21am UTC](https://discuss.elastic.co/t/updating-a-document-using-java-api/18165/3 "2017-07-06T01:21:28Z")

</div>


