# Upsert Document on the basis of datetime format

**URL:** https://discuss.elastic.co/t/upsert-document-on-the-basis-of-datetime-format/243864
**Category:** Elasticsearch
**Created:** [August 5, 2020, 12:22pm UTC](https://discuss.elastic.co/t/upsert-document-on-the-basis-of-datetime-format/243864 "2020-08-05T12:22:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![rishabh\_jain](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@rishabh\_jain](https://discuss.elastic.co/u/rishabh_jain)
#### Post date: [August 5, 2020, 12:22pm UTC](https://discuss.elastic.co/t/upsert-document-on-the-basis-of-datetime-format/243864/1 "2020-08-05T12:22:31Z")

</div>

Hello,

If I wanted to update an existing document if it satisfies the condition. See an example below:

Index: test\_index

1. Add tweet and lastupdated fields to document 1 as below. Please note that the lastupdated field is of type date and has epoch value.  
PUT test\_index  
{  
"tweet" : "tweet1",  
"lastupdated" : "2019-04-04T12:01:42.834Z"  
}

2. I want to update the document only if the updated\_at greater than the current existing.

how can i write this using script?

---

<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: [September 2, 2020, 12:22pm UTC](https://discuss.elastic.co/t/upsert-document-on-the-basis-of-datetime-format/243864/2 "2020-09-02T12:22:35Z")

</div>

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