# Ttl with node js

**URL:** <https://discuss.elastic.co/t/ttl-with-node-js/113908>\
**Category:** Elasticsearch\
**Created:** [January 3, 2018, 10:56am UTC](https://discuss.elastic.co/t/ttl-with-node-js/113908 "2018-01-03T10:56:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramveer](https://avatars.discourse-cdn.com/v4/letter/r/e5b9ba/32.png) [@ramveer](https://discuss.elastic.co/u/ramveer)\
**Post date:** [January 3, 2018, 10:56am UTC](https://discuss.elastic.co/t/ttl-with-node-js/113908/1 "2018-01-03T10:56:24Z")

</div>

I want to set ttl to a document using node js(ts) :  
below is the code  
private setTTL(indexName: string, indexType: string) {  
console.log("\*\*\*\*\*\*\*\*\*\*\*\*\*index: "+indexName+" and type is : "+indexType);  
console.log("config.api.header\_info\_ttl: "+config.api.header\_info\_ttl);  
this.elasticClient.indices.putMapping({  
index: indexName,  
type: indexType,  
body: {  
"header\_info": {  
'\_ttl': {  
"enabled": true,  
'default': config.api.header\_info\_ttl  
}  
}  
}  
})  
.then(function (result) {  
console.log('&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&result', result)  
})  
}

but when I try to execute it below is the error I am getting:

```
(node:51812) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): [mapper_parsing_exception] Root mapping definition has unsupported parameters: [header_info : {_ttl={enabled=true, default=1m}}] :: {"path":"/api_connector_rs/_mapping/header_info_rs","query":{},"body":"{\"header_info\":{\"_ttl\":{\"enabled\":true,\"default\":\"1m\"}}}","statusCode":400,"response":"{\"error\":{\"root_cause\":[{\"type\":\"mapper_parsing_exception\",\"reason\":\"Root mapping definition has unsupported parameters: [header_info : {_ttl={enabled=true, default=1m}}]\"}],\"type\":\"mapper_parsing_exception\",\"reason\":\"Root mapping definition has unsupported parameters: [header_info : {_ttl={enabled=true, default=1m}}]\"},\"status\":400}"}

```

I am using ES version : 6.0.1

I read it somewhere it ttl is not supported after 2.4 versions, What is the alternate to delete a document in elastic search using node js

Thanks

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [January 6, 2018, 3:29pm UTC](https://discuss.elastic.co/t/ttl-with-node-js/113908/2 "2018-01-06T15:29:43Z")

</div>

Indeed TTL is not supported anymore. If you to just delete a document then check this [https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-delete](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-delete)

---

<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:** [February 3, 2018, 3:29pm UTC](https://discuss.elastic.co/t/ttl-with-node-js/113908/3 "2018-02-03T15:29:58Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
