# Can't get ttl to work

**URL:** <https://discuss.elastic.co/t/cant-get-ttl-to-work/7445>\
**Category:** Elasticsearch\
**Created:** [April 23, 2012, 7:38pm UTC](https://discuss.elastic.co/t/cant-get-ttl-to-work/7445 "2012-04-23T19:38:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Ridley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_ridley/32/2906_2.png) [@Nathan\_Ridley](https://discuss.elastic.co/u/Nathan_Ridley)\
**Post date:** [April 23, 2012, 7:38pm UTC](https://discuss.elastic.co/t/cant-get-ttl-to-work/7445/1 "2012-04-23T19:38:06Z")

</div>

Going out of my brain trying to get ttl to work! Here are my current  
settings. Note that I have tried both \_ttl and ttl in the settings below:

{

- domains:  
{
  - settings:  
{
    - index.analysis.analyzer.standard.type: "standard",
    - index.analysis.analyzer.default.stopwords.0: "\_no\_stop\_words",
    - index.mappings.public.properties.list.all.type: "nested",
    - index.mappings.user.properties.list.all.type: "nested",
    - index.source.compress: "true",
    - index.source.enabled: "true",
    - index.merge.policy.merge\_factor: "3",
    - index.mappings.public.\_ttl.enabled: "true",
    - index.analysis.analyzer.default.type: "standard",
    - index.mappings.public.\_timestamp.enabled: "true",
    - index.number\_of\_shards: "5",
    - index.number\_of\_replicas: "1",
    - index.version.created: "190299"  
}  
}

}

in addition I have tried this _http://....../domains/public/\_mapping_ with \*  
PUT\* and a request body of: {"public":{"ttl":{"enabled":true}}}

Again, I have tried both ttl and \_ttl in the mapping request body. When am  
I supposed to use underscores and when am I not? I can't quite get a handle  
on that.

After trying to set the ttl mapping, calling \_settings on _public_ doesn't  
show the actual ttl value I set, suggesting I either set it incorrectly or  
the ttl value is hidden:

{

- public:  
{
  - properties:  
{
    - foo:  
{
      - type: "string"  
}  
}  
}

}

I've tried setting ttl in the document using the querystring: ?ttl=30s  
And in the json body: { "foo":"bar", "\_ttl":"30s" }  
Just in case "30s" was wrong, I've also tried using 30000 (milliseconds).

Nothing I do causes the document to expire. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![Nathan\_Ridley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_ridley/32/2906_2.png) [@Nathan\_Ridley](https://discuss.elastic.co/u/Nathan_Ridley)\
**Post date:** [April 23, 2012, 8:00pm UTC](https://discuss.elastic.co/t/cant-get-ttl-to-work/7445/2 "2012-04-23T20:00:21Z")

</div>

never mind, I got it to work.

On Monday, April 23, 2012 8:38:06 PM UTC+1, Nathan Ridley wrote:

> Going out of my brain trying to get ttl to work! Here are my current  
> settings. Note that I have tried both \_ttl and ttl in the settings below:
> 
> {
> 
> - domains:  
> {
> - settings:  
> {
> - index.analysis.analyzer.standard.type: "standard",
> - index.analysis.analyzer.default.stopwords.0: "\_no\_stop\_words",
> - index.mappings.public.properties.list.all.type: "nested",
> - index.mappings.user.properties.list.all.type: "nested",
> - index.source.compress: "true",
> - index.source.enabled: "true",
> - index.merge.policy.merge\_factor: "3",
> - index.mappings.public.\_ttl.enabled: "true",
> - index.analysis.analyzer.default.type: "standard",
> - index.mappings.public.\_timestamp.enabled: "true",
> - index.number\_of\_shards: "5",
> - index.number\_of\_replicas: "1",
> - index.version.created: "190299"  
> }  
> }
> 
> }
> 
> in addition I have tried this _http://....../domains/public/\_mapping_ with  
> _PUT_ and a request body of: {"public":{"ttl":{"enabled":true}}}
> 
> Again, I have tried both ttl and \_ttl in the mapping request body. When am  
> I supposed to use underscores and when am I not? I can't quite get a handle  
> on that.
> 
> After trying to set the ttl mapping, calling \_settings on _public_ doesn't  
> show the actual ttl value I set, suggesting I either set it incorrectly or  
> the ttl value is hidden:
> 
> {
> 
> - public:  
> {
> - properties:  
> {
> - foo:  
> {
> - type: "string"  
> }  
> }  
> }
> 
> }
> 
> I've tried setting ttl in the document using the querystring: ?ttl=30s  
> And in the json body: { "foo":"bar", "\_ttl":"30s" }  
> Just in case "30s" was wrong, I've also tried using 30000 (milliseconds).
> 
> Nothing I do causes the document to expire. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![dib\_g](https://avatars.discourse-cdn.com/v4/letter/d/b5e925/32.png) [@dib\_g](https://discuss.elastic.co/u/dib_g)\
**Post date:** [October 1, 2013, 9:15pm UTC](https://discuss.elastic.co/t/cant-get-ttl-to-work/7445/3 "2013-10-01T21:15:54Z")

</div>

Hi Nathan,

Can you please tell me how did you get the ttl field to work for your ES setup? My mapping JSON is posted here: [http://pastebin.com/4K8ZdxFH](http://pastebin.com/4K8ZdxFH)

I have sorted through tons of documentation online / offline but just can't make it working.

Any help will be extremely helpful.

Thanks,

- d

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 6, 2013, 4:48pm UTC](https://discuss.elastic.co/t/cant-get-ttl-to-work/7445/4 "2013-10-06T16:48:35Z")

</div>

Hey,

can you maybe explain, for what index you expect what kind of behaviour,  
just to manage expectations?

This is a sample for TTL, but maybe you want to have some additional  
features?

curl -X DELETE localhost:9200/test  
curl -X PUT localhost:9200/test

curl -X PUT localhost:9200/test/tweet/\_mapping -d '{  
"tweet" : {  
"\_ttl" : { "enabled" : true }  
}  
}'

curl -X PUT 'localhost:9200/test/tweet/1?ttl=1m' -d '{  
"foo" : "bar"  
}'

curl -X GET localhost:9200/test/tweet/1

sleep 120

curl -X GET localhost:9200/test/tweet/1

You will see in the last GET call, that the document has been removed. Also  
note, that the pruning process, which removes stale documents, runs every  
60 seconds, so it may last up to 120 seconds, until documents are really  
deleted. You can configure that interval via the indices.ttl.interval  
setting.

If you have further questions, feel free to ask.

--Alex

On Tue, Oct 1, 2013 at 11:15 PM, dib.g [dibyajyotighosh@gmail.com](mailto:dibyajyotighosh@gmail.com) wrote:

> Hi Nathan,
> 
> Can you please tell me how did you get the ttl field to work for your ES  
> setup? My mapping JSON is posted here: [es-mapping.json - Pastebin.com](http://pastebin.com/4K8ZdxFH)
> 
> I have sorted through tons of documentation online / offline but just can't  
> make it working.
> 
> Any help will be extremely helpful.
> 
> Thanks,
> 
> - d
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/can-t-get-ttl-to-work-tp3933447p4041990.html](http://elasticsearch-users.115913.n3.nabble.com/can-t-get-ttl-to-work-tp3933447p4041990.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:13am UTC](https://discuss.elastic.co/t/cant-get-ttl-to-work/7445/5 "2017-07-06T02:13:30Z")

</div>


