# Updating default ttl value in elasticsearch?

**URL:** <https://discuss.elastic.co/t/updating-default-ttl-value-in-elasticsearch/55971>\
**Category:** Elasticsearch\
**Created:** [July 20, 2016, 10:59am UTC](https://discuss.elastic.co/t/updating-default-ttl-value-in-elasticsearch/55971 "2016-07-20T10:59:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajind\_Ruparathna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajind_ruparathna/32/10545_2.png) [@Rajind\_Ruparathna](https://discuss.elastic.co/u/Rajind_Ruparathna)\
**Post date:** [July 20, 2016, 10:59am UTC](https://discuss.elastic.co/t/updating-default-ttl-value-in-elasticsearch/55971/1 "2016-07-20T10:59:28Z")

</div>

I know that when creating the mapping we can give something like,

```
        "_ttl" : {
          "enabled" : true,
          "default" : 900000
        }

```

to enable \_ttl with a default value. I would like to know whether can be update this default \_ttl value by updating the mapping ?

Thanks. Any help is highly appreciated.

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [July 20, 2016, 12:10pm UTC](https://discuss.elastic.co/t/updating-default-ttl-value-in-elasticsearch/55971/2 "2016-07-20T12:10:16Z")

</div>

Hi @Rajind_Ruparathna,

let me start by pointing out that [\_ttl is deprecated in Elasticsearch 2.x](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/breaking_20_mapping_changes.html#_literal __timestamp_literal_and_literal__ ttl_literal_deprecated).

Did you try to update the mapping?

Here is a complete example that worked fine for me (tested with Elasticsearch 2.3.4):

```auto
DELETE /my_index

PUT /my_index
{
  "mappings": {
    "my_type": {
      "_ttl": {
        "enabled": true,
        "default": "1m"
      }
    }
  }
}

PUT /my_index/my_type/1
{
  "text": "Will expire in 1 minute"
}

GET /my_index/my_type/1

PUT /my_index/_mapping/my_type
{
      "_ttl": {
         "enabled": true,
         "default": "24h"
      }
}

PUT /my_index/my_type/2
{
  "text": "Will expire in a day"
}

GET /my_index/my_type/2

```

Daniel

---

<div class="post-metadata">

**Author:** ![Rajind\_Ruparathna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajind_ruparathna/32/10545_2.png) [@Rajind\_Ruparathna](https://discuss.elastic.co/u/Rajind_Ruparathna)\
**Post date:** [July 20, 2016, 12:26pm UTC](https://discuss.elastic.co/t/updating-default-ttl-value-in-elasticsearch/55971/3 "2016-07-20T12:26:34Z")

</div>

Thanks. I will try that. I did try to update the mapping but got indexAlreadyExistsException. I was doing something wrong back then.

---

<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:** [July 20, 2016, 12:38pm UTC](https://discuss.elastic.co/t/updating-default-ttl-value-in-elasticsearch/55971/4 "2016-07-20T12:38:32Z")

</div>

If you get that it is usually because you are using the create index API to  
update the mapping. They look fairly similar and I've mixed them up a few  
times so I know the error message well.

---

<div class="post-metadata">

**Author:** ![Rajind\_Ruparathna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajind_ruparathna/32/10545_2.png) [@Rajind\_Ruparathna](https://discuss.elastic.co/u/Rajind_Ruparathna)\
**Post date:** [July 20, 2016, 12:54pm UTC](https://discuss.elastic.co/t/updating-default-ttl-value-in-elasticsearch/55971/5 "2016-07-20T12:54:51Z")

</div>

yes. that was the issue. thanks.

---

<div class="post-metadata">

**Author:** ![Rajind\_Ruparathna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajind_ruparathna/32/10545_2.png) [@Rajind\_Ruparathna](https://discuss.elastic.co/u/Rajind_Ruparathna)\
**Post date:** [July 20, 2016, 12:58pm UTC](https://discuss.elastic.co/t/updating-default-ttl-value-in-elasticsearch/55971/6 "2016-07-20T12:58:31Z")

</div>

@nik9000, @danielmitterdorfer One small question, say I have set a default \_ttl value and now i want to update the mapping so that there is no such default ttl value. I've tried with,  
{  
"\_ttl": {  
"enabled": true,  
}  
}

but doesn't seem to remove the default \_ttl value.

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [July 20, 2016, 1:06pm UTC](https://discuss.elastic.co/t/updating-default-ttl-value-in-elasticsearch/55971/7 "2016-07-20T13:06:37Z")

</div>

Hi @Rajind_Ruparathna,

that's correct. This is not possible. Issuing:

```auto
PUT /my_index/_mapping/my_type
{
      "_ttl": {
         "enabled": false
      }
}

```

throws an error:

```auto
{
   "error": {
      "root_cause": [
         {
            "type": "illegal_argument_exception",
            "reason": "_ttl cannot be disabled once it was enabled."
         }
      ],
      "type": "illegal_argument_exception",
      "reason": "_ttl cannot be disabled once it was enabled."
   },
   "status": 400
}

```

You have to create a new index if you need to disable it.

Daniel

---

<div class="post-metadata">

**Author:** ![Rajind\_Ruparathna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajind_ruparathna/32/10545_2.png) [@Rajind\_Ruparathna](https://discuss.elastic.co/u/Rajind_Ruparathna)\
**Post date:** [July 20, 2016, 4:53pm UTC](https://discuss.elastic.co/t/updating-default-ttl-value-in-elasticsearch/55971/8 "2016-07-20T16:53:28Z")

</div>

Yes. I tried and got the same result. Thanks. cheers.

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [July 21, 2016, 5:28am UTC](https://discuss.elastic.co/t/updating-default-ttl-value-in-elasticsearch/55971/9 "2016-07-21T05:28:18Z")

</div>

You're welcome. Glad that I could help you.

---

<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/updating-default-ttl-value-in-elasticsearch/55971/10 "2017-07-05T22:33:51Z")

</div>


