# Elasticsearch - Timestamp based document Upsert

**URL:** https://discuss.elastic.co/t/elasticsearch-timestamp-based-document-upsert/265688
**Category:** Elasticsearch
**Created:** [February 27, 2021, 11:34am UTC](https://discuss.elastic.co/t/elasticsearch-timestamp-based-document-upsert/265688 "2021-02-27T11:34:45Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![tag\_v](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tag_v/32/47466_2.png) [@tag\_v](https://discuss.elastic.co/u/tag_v)
#### Post date: [February 27, 2021, 11:34am UTC](https://discuss.elastic.co/t/elasticsearch-timestamp-based-document-upsert/265688/1 "2021-02-27T11:34:45Z")

</div>

I am looking for more efficient and performance way to implement below use case:

- Every input JSON contains event\_timestamp and document\_id field. document\_id is '\_id' for the index.
- If a document with document\_id already exists in index and event\_timestamp of new input json is latest than existing document's event\_timestamp, perform update operation
- If a document with document\_id already exists in index, but, event\_timestamp of new input json is older than existing document's event\_timestamp, no operations
- If document with document\_id not exists in index, perform insert operation

Currently, I am performing 2 round trip calls to from Elasticsearch. Is there any better way to do similar to hbase timestamp column which stores latest timestamp event ?

Thanks in Advance.

---

<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: [March 27, 2021, 11:35am UTC](https://discuss.elastic.co/t/elasticsearch-timestamp-based-document-upsert/265688/2 "2021-03-27T11:35:26Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
