# Any alternative for \_ttl mapping

**URL:** <https://discuss.elastic.co/t/any-alternative-for--ttl-mapping/53367>\
**Category:** Elasticsearch\
**Created:** [June 20, 2016, 8:05pm UTC](https://discuss.elastic.co/t/any-alternative-for--ttl-mapping/53367 "2016-06-20T20:05:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandipelastic](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@sandipelastic](https://discuss.elastic.co/u/sandipelastic)\
**Post date:** [June 20, 2016, 8:05pm UTC](https://discuss.elastic.co/t/any-alternative-for--ttl-mapping/53367/1 "2016-06-20T20:05:17Z")

</div>

I am using Elasticsearch 2.3.3 and I found out that \_ttl (time to live) mapping was deprecated. I am wondering if there is any alternative mapping for automatic deletion of documents. Any comments and suggestions would be helpful.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [June 20, 2016, 8:20pm UTC](https://discuss.elastic.co/t/any-alternative-for--ttl-mapping/53367/2 "2016-06-20T20:20:34Z")

</div>

> [@sandipelastic](#):
>
> mapping for automatic deletion of documents

No mapping, but usually we recommend using time based indexes. Like make an index every day or week or something and remove it when you don't need it. The trouble with ttl is that removing documents is way way more costly than removing indexes.

You can certainly add a timestamp field to the document (not `_timestamp`, that too is deprecated) and do a delete-by-query with a range of timestamps. And that is a fine thing to do on a small index, but it is only fine if the index is small.

---

<div class="post-metadata">

**Author:** ![sandipelastic](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@sandipelastic](https://discuss.elastic.co/u/sandipelastic)\
**Post date:** [July 20, 2016, 6:10pm UTC](https://discuss.elastic.co/t/any-alternative-for--ttl-mapping/53367/3 "2016-07-20T18:10:48Z")

</div>

As per your suggestion, I used delete-by-query but I am getting following exception

**{"error":{"root\_cause":[{"type":"parse\_exception","reason":"Failed to derive xcontent"}],"type":"search\_phase\_execution\_exception","reason":"all shards failed","phase":"query"**  
**,"grouped":true,"failed\_shards":[{"shard":0,"index":"accounts\_test\_power\_user","node":"2V96EnCPRJevhWIUs-yeRA","reason":{"type":"parse\_exception","reason":"Failed to derive xc**  
**ontent"}}]},"status":400}**

I created "accounts\_test\_power\_user" index with mappings(expiration\_date is one field) and I gave mapping for expiration\_date

"expiration\_date" : {  
"type" : "date",  
"format" : "MM/dd/yyyy"  
}

For delete-by-query, I used below curl request

curl --XDELETE [http://localhost:9200/accounts\_test\_power\_user/external/\_query](http://localhost:9200/accounts_test_power_user/external/_query) -d'{"filter":{"range":{"expiration\_date":{"lte":"12/19/2016","format":"MM/dd/yyyy"}}}}'

Please suggest me if I can use this approach to delete the data.

---

<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 5, 2017, 10:33pm UTC](https://discuss.elastic.co/t/any-alternative-for--ttl-mapping/53367/4 "2017-07-05T22:33:57Z")

</div>


