# Query the doc before update

**URL:** <https://discuss.elastic.co/t/query-the-doc-before-update/128599>\
**Category:** Logstash\
**Created:** [April 18, 2018, 8:22pm UTC](https://discuss.elastic.co/t/query-the-doc-before-update/128599 "2018-04-18T20:22:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brunoof1](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@brunoof1](https://discuss.elastic.co/u/brunoof1)\
**Post date:** [April 18, 2018, 8:22pm UTC](https://discuss.elastic.co/t/query-the-doc-before-update/128599/1 "2018-04-18T20:22:38Z")

</div>

I want to get a doc before update, follow the example.

1º Event  
{"date\_sent":"2018-04-18T13:57:42.005","token":"1"}]

2º Event  
{"date\_open":"2018-04-18T14:57:42.005","token":"1"}]

3º Event  
{"date\_open":"2018-04-18T15:57:42.005","token":"1"}]

I don't want update date\_open from third time, so whenever the end user opens an e-mail, i will write just the first date\_open.

Data on 1º Event

"date\_sent":"2018-04-18T13:57:42.005"  
"token":"1"  
"type":"e-mail"

Data on 2º Event

"date\_sent":"2018-04-18T13:57:42.005"  
"date\_open":"2018-04-18T14:57:42.005"  
"token":"1"  
"type":"e-mail"

Data on 3º Event

"date\_sent":"2018-04-18T13:57:42.005"  
"date\_open":"2018-04-18T14:57:42.005"  
"token":"1"  
"type":"e-mail"

Date\_open must be writen at the first time but never updated !

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [April 20, 2018, 3:45am UTC](https://discuss.elastic.co/t/query-the-doc-before-update/128599/2 "2018-04-20T03:45:45Z")

</div>

You should be able to do that with [Scripted Update](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#_scripted_updates)

---

<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:** [May 18, 2018, 3:45am UTC](https://discuss.elastic.co/t/query-the-doc-before-update/128599/3 "2018-05-18T03:45:51Z")

</div>

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