# \_ttl attribute not taken into account

**URL:** <https://discuss.elastic.co/t/-ttl-attribute-not-taken-into-account/25783>\
**Category:** Elasticsearch\
**Created:** [July 17, 2015, 9:29am UTC](https://discuss.elastic.co/t/-ttl-attribute-not-taken-into-account/25783 "2015-07-17T09:29:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antoine\_Brun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/antoine_brun/32/3774_2.png) [@Antoine\_Brun](https://discuss.elastic.co/u/Antoine_Brun)\
**Post date:** [July 17, 2015, 9:29am UTC](https://discuss.elastic.co/t/-ttl-attribute-not-taken-into-account/25783/1 "2015-07-17T09:29:17Z")

</div>

Hello,

I have implemented a simple cache with ES.  
Basically I rely on \_ttl to make sure that the cache is cleaned up automatically.  
below is a partial view of the doc stored in the cache.  
As you can see: **\_ttl=5d** and the date of the doc is **2015-06-30** which is more that 5 days old.

Any idea why the doc was not deleted from the index?

Antoine

```
{
"_index": "ubilogs-ncs-15.2.2_cache",
"_type": "cache",
"_id": "AU5E8nqFbXvxIKWU75lr",
"_version": 1,
"_score": null,
"_source": {
    "_ttl": "5d",
    "device_id": "NTT1141",
    "msg_id": "000000585107",
    "content": {
        "disk": {
            "date": "2015-06-30",
            "time": "23:30:51",
           "msg_id": "000000585107",
           "device_id": "FVVM020000038360",
            "policy": "to_MSActivator",
  ...
```

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 17, 2015, 9:55am UTC](https://discuss.elastic.co/t/-ttl-attribute-not-taken-into-account/25783/2 "2015-07-17T09:55:01Z")

</div>

Have you enabled TTL in the mapping?

[https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-ttl-field.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-ttl-field.html)

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 17, 2015, 9:56am UTC](https://discuss.elastic.co/t/-ttl-attribute-not-taken-into-account/25783/3 "2015-07-17T09:56:26Z")

</div>

The `_ttl` field needs to be used with the `_timestamp` field. This is the field that it looks at to determine the expiry time.Are you setting the `_timestamp` in your documents? See [https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index\_.html#index-ttl](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#index-ttl) for more information.

---

<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:00am UTC](https://discuss.elastic.co/t/-ttl-attribute-not-taken-into-account/25783/4 "2017-07-06T00:00:50Z")

</div>


