# Saving "newest" document

**URL:** https://discuss.elastic.co/t/saving-newest-document/13055
**Category:** Elasticsearch
**Created:** [August 3, 2013, 6:04pm UTC](https://discuss.elastic.co/t/saving-newest-document/13055 "2013-08-03T18:04:50Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Victor\_D](https://avatars.discourse-cdn.com/v4/letter/v/b9e5f3/32.png) [@Victor\_D](https://discuss.elastic.co/u/Victor_D)
#### Post date: [August 3, 2013, 6:04pm UTC](https://discuss.elastic.co/t/saving-newest-document/13055/1 "2013-08-03T18:04:50Z")

</div>

If I have a document, that's being saved with a key, and a document already  
exists with that same key, is there any way to only save "newest" document?  
For example, if I have a key abc, and a date 2013-08-10 and a document  
comes in with key abc and an older date, any way to let es know and ignore  
the update, since the document is older? And if a newer document comes in,  
then overwrite abc with newer document. I am concerned that if I pull the  
value to compare in the code, then in a multi-threaded environment, I could  
still lose the latest doc. Not to say that same can't happen within ES, but  
just curious if I set \_version field or something to time stamp, would that  
do anything or any way to force saving only latest?

Thanks  
Victor

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [August 3, 2013, 6:22pm UTC](https://discuss.elastic.co/t/saving-newest-document/13055/2 "2013-08-03T18:22:06Z")

</div>

See versioning in [http://www.elasticsearch.org/guide/reference/api/index\_/](http://www.elasticsearch.org/guide/reference/api/index_/)

I think that setting version\_type to external could help here. Send date in ms as version number.  
You should get failures in case of indexing with an older value.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 3 août 2013 à 20:04, Victor D [vmv890@gmail.com](mailto:vmv890@gmail.com) a écrit :

If I have a document, that's being saved with a key, and a document already exists with that same key, is there any way to only save "newest" document?  
For example, if I have a key abc, and a date 2013-08-10 and a document comes in with key abc and an older date, any way to let es know and ignore the update, since the document is older? And if a newer document comes in, then overwrite abc with newer document. I am concerned that if I pull the value to compare in the code, then in a multi-threaded environment, I could still lose the latest doc. Not to say that same can't happen within ES, but just curious if I set \_version field or something to time stamp, would that do anything or any way to force saving only latest?

## Thanks Victor

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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:23am UTC](https://discuss.elastic.co/t/saving-newest-document/13055/3 "2017-07-06T02:23:07Z")

</div>


