# Doc\_as\_update and ttl

**URL:** <https://discuss.elastic.co/t/doc-as-update-and-ttl/21779>\
**Category:** Elasticsearch\
**Created:** [January 22, 2015, 3:37pm UTC](https://discuss.elastic.co/t/doc-as-update-and-ttl/21779 "2015-01-22T15:37:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shmish111](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shmish111/32/950_2.png) [@shmish111](https://discuss.elastic.co/u/shmish111)\
**Post date:** [January 22, 2015, 3:37pm UTC](https://discuss.elastic.co/t/doc-as-update-and-ttl/21779/1 "2015-01-22T15:37:59Z")

</div>

Hi,

I want to upsert a document and at the same time reset it's TTL. I.e. To  
do the upsert I use \_update with doc\_as\_update true and to update the ttl I  
use \_update with script and ctx.\_ttl. It seems I can't do both of these at  
the same time though. Does this mean I have to do one of:

1. Two queries, one to upsert, the other to set ttl
2. Write a script that upserts the doc from a parameter and updates the ttl

How would I go about doing 2. or do scripts only work on existing documents?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/dcb08f30-fe38-4f3a-83ed-399a9f2214e8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/dcb08f30-fe38-4f3a-83ed-399a9f2214e8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:37am UTC](https://discuss.elastic.co/t/doc-as-update-and-ttl/21779/2 "2017-07-06T00:37:13Z")

</div>


