# Update Document

**URL:** <https://discuss.elastic.co/t/update-document/2911>\
**Category:** Elasticsearch\
**Created:** [April 15, 2010, 8:28pm UTC](https://discuss.elastic.co/t/update-document/2911 "2010-04-15T20:28:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexandre\_gerlic](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@alexandre\_gerlic](https://discuss.elastic.co/u/alexandre_gerlic)\
**Post date:** [April 15, 2010, 8:28pm UTC](https://discuss.elastic.co/t/update-document/2911/1 "2010-04-15T20:28:12Z")

</div>

Hi,

I would like to know if it is possible to update a document, for  
example replace or add a field ?  
I found optype = create but it seems to be the only solution.

Thanks

--  
Alexandre Gerlic

---

<div class="post-metadata">

**Author:** ![Berkay\_Mollamustafao](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@Berkay\_Mollamustafao](https://discuss.elastic.co/u/Berkay_Mollamustafao)\
**Post date:** [April 15, 2010, 8:31pm UTC](https://discuss.elastic.co/t/update-document/2911/2 "2010-04-15T20:31:26Z")

</div>

The default index command updates the document if it exists. optype create  
just says don't check whether it exists to improve performance. So if you  
want to update the doc, I think you just index it again.

Regards,  
Berkay Mollamustafaoglu  
mberkay on yahoo, google and skype

On Thu, Apr 15, 2010 at 4:28 PM, alexandre gerlic \<  
[alexandre.gerlic@gmail.com](mailto:alexandre.gerlic@gmail.com)\> wrote:

> Hi,
> 
> I would like to know if it is possible to update a document, for  
> example replace or add a field ?  
> I found optype = create but it seems to be the only solution.
> 
> Thanks
> 
> --  
> Alexandre Gerlic

---

<div class="post-metadata">

**Author:** ![alexandre\_gerlic](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@alexandre\_gerlic](https://discuss.elastic.co/u/alexandre_gerlic)\
**Post date:** [April 15, 2010, 8:38pm UTC](https://discuss.elastic.co/t/update-document/2911/3 "2010-04-15T20:38:33Z")

</div>

2010/4/15 Berkay Mollamustafaoglu [mberkay@gmail.com](mailto:mberkay@gmail.com):

> The default index command updates the document if it exists. optype create  
> just says don't check whether it exists to improve performance. So if you  
> want to update the doc, I think you just index it again.  
> Regards,  
> Berkay Mollamustafaoglu

Thanks, I found also this in put mapping section :  
"When an existing mapping already exists under the given type, the two  
mapping definitions, the one already defined, and the new ones are  
merged."

> mberkay on yahoo, google and skype
> 
> On Thu, Apr 15, 2010 at 4:28 PM, alexandre gerlic  
> [alexandre.gerlic@gmail.com](mailto:alexandre.gerlic@gmail.com) wrote:
> 
> > Hi,
> > 
> > I would like to know if it is possible to update a document, for  
> > example replace or add a field ?  
> > I found optype = create but it seems to be the only solution.
> > 
> > Thanks
> > 
> > --  
> > Alexandre Gerlic

--  
Alexandre Gerlic

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [April 15, 2010, 9:29pm UTC](https://discuss.elastic.co/t/update-document/2911/4 "2010-04-15T21:29:47Z")

</div>

> Thanks, I found also this in put mapping section :  
> "When an existing mapping already exists under the given type, the two  
> mapping definitions, the one already defined, and the new ones are  
> merged."

...if they can be

If you have a field defined as 'string', then you want to change it to  
'date', you can't do that. You would need to create a new mapping and  
reindex all the existing documents.

I have it working as follows:

- my app uses index 'xyz'
- 'xyz' is an alias for 'xyz\_1234'

if I want to change the mapping:

- I create 'xyz\_1235'
- read all docs from 'xyz\_1234' -\> index to 'xyz\_1235'
- update alias 'xyz' to point to 'xyz\_1235'
- delete index 'xyz\_1234'

--  
Web Announcements Limited is a company registered in England and Wales,  
with company number 05608868, with registered address at 10 Arvon Road,  
London, N5 1PR.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 16, 2010, 10:05am UTC](https://discuss.elastic.co/t/update-document/2911/5 "2010-04-16T10:05:37Z")

</div>

Note that this are two different things, updating the mapping and updating a  
document instance.

cheer,  
shay.banon

On Fri, Apr 16, 2010 at 12:29 AM, Clinton Gormley  
[clinton@iannounce.co.uk](mailto:clinton@iannounce.co.uk)wrote:

> > Thanks, I found also this in put mapping section :  
> > "When an existing mapping already exists under the given type, the two  
> > mapping definitions, the one already defined, and the new ones are  
> > merged."
> 
> ...if they can be
> 
> If you have a field defined as 'string', then you want to change it to  
> 'date', you can't do that. You would need to create a new mapping and  
> reindex all the existing documents.
> 
> I have it working as follows:
> 
> - my app uses index 'xyz'
> - 'xyz' is an alias for 'xyz\_1234'
> 
> if I want to change the mapping:
> 
> - I create 'xyz\_1235'
> - read all docs from 'xyz\_1234' -\> index to 'xyz\_1235'
> - update alias 'xyz' to point to 'xyz\_1235'
> - delete index 'xyz\_1234'
> 
> --  
> Web Announcements Limited is a company registered in England and Wales,  
> with company number 05608868, with registered address at 10 Arvon Road,  
> London, N5 1PR.

---

<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, 4:24am UTC](https://discuss.elastic.co/t/update-document/2911/6 "2017-07-06T04:24:37Z")

</div>


