# What's the timeunit of setTTL(long ttl) in IndexRequestBuilder?

**URL:** <https://discuss.elastic.co/t/whats-the-timeunit-of-setttl-long-ttl-in-indexrequestbuilder/15943>\
**Category:** Elasticsearch\
**Created:** [February 21, 2014, 9:40am UTC](https://discuss.elastic.co/t/whats-the-timeunit-of-setttl-long-ttl-in-indexrequestbuilder/15943 "2014-02-21T09:40:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Guo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_guo/32/1725_2.png) [@Daniel\_Guo](https://discuss.elastic.co/u/Daniel_Guo)\
**Post date:** [February 21, 2014, 9:40am UTC](https://discuss.elastic.co/t/whats-the-timeunit-of-setttl-long-ttl-in-indexrequestbuilder/15943/1 "2014-02-21T09:40:44Z")

</div>

I'm trying to set documents sent to elasticsearch with TTL in Java.

I call the method setTTL of IndexRequestBuilder when indexing documents.  
But I don't know what the time unit and I cannot find in docs and api.

Could anybody helps, Thanks.

--  
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/dd982469-3aca-4ede-b0ae-e564ce684c27%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/dd982469-3aca-4ede-b0ae-e564ce684c27%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 21, 2014, 1:38pm UTC](https://discuss.elastic.co/t/whats-the-timeunit-of-setttl-long-ttl-in-indexrequestbuilder/15943/2 "2014-02-21T13:38:44Z")

</div>

It should be milliseconds.

--  
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/fba8041e-a40a-4d73-af4a-a17f9241d602%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fba8041e-a40a-4d73-af4a-a17f9241d602%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Daniel\_Guo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_guo/32/1725_2.png) [@Daniel\_Guo](https://discuss.elastic.co/u/Daniel_Guo)\
**Post date:** [February 21, 2014, 4:04pm UTC](https://discuss.elastic.co/t/whats-the-timeunit-of-setttl-long-ttl-in-indexrequestbuilder/15943/3 "2014-02-21T16:04:17Z")

</div>

@Binh, thank you, you are right, I find the reference here:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

but the problem is that, the TTL doesn't work when indexing a document,  
while it works when defined in type mapping. The user encountered the same  
problem with me:

> <https://stackoverflow.com/questions/16914864/how-to-make-elasticsearch-document-ttl-work>

Actually I don't know why.

On Friday, February 21, 2014 9:38:44 PM UTC+8, Binh Ly wrote:

> It should be milliseconds.

--  
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/eab07716-d4ad-4266-aedc-3762c67fedb5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/eab07716-d4ad-4266-aedc-3762c67fedb5%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 21, 2014, 5:02pm UTC](https://discuss.elastic.co/t/whats-the-timeunit-of-setttl-long-ttl-in-indexrequestbuilder/15943/4 "2014-02-21T17:02:27Z")

</div>

That is correct, the \_ttl field is disabled by default:

[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-ttl-field.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-ttl-field.html)

To use TTL, you need to enable it first in the mapping and then after that  
you can index documents with a TTL value and it will work as expected.

--  
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/1c1a605f-779b-448b-bc48-d861fc24afb9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1c1a605f-779b-448b-bc48-d861fc24afb9%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Daniel\_Guo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_guo/32/1725_2.png) [@Daniel\_Guo](https://discuss.elastic.co/u/Daniel_Guo)\
**Post date:** [February 22, 2014, 12:42am UTC](https://discuss.elastic.co/t/whats-the-timeunit-of-setttl-long-ttl-in-indexrequestbuilder/15943/5 "2014-02-22T00:42:50Z")

</div>

@Binh, enable ttl first in mapping and then use it in REST or client, it  
make sense. Thank you again!

On Saturday, February 22, 2014 1:02:27 AM UTC+8, Binh Ly wrote:

> That is correct, the \_ttl field is disabled by default:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-ttl-field.html)
> 
> To use TTL, you need to enable it first in the mapping and then after that  
> you can index documents with a TTL value and it will work as expected.

--  
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/49d43974-4b9b-489d-b863-7ff4d9495746%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/49d43974-4b9b-489d-b863-7ff4d9495746%40googlegroups.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, 1:48am UTC](https://discuss.elastic.co/t/whats-the-timeunit-of-setttl-long-ttl-in-indexrequestbuilder/15943/6 "2017-07-06T01:48:12Z")

</div>


