I am using elasticsearch-model (https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model) but I can't find a way to set the TTL on the documents. I have tried a few ways but without success.
I have a model called "log" and an index called "logs". In the model I have the following mappings:
include Elasticsearch::Model
mappings _ttl: { enabled: true, default: '7d' }
Which I was hoping it would be similar to https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-ttl-field.html#mapping-ttl-field
In the console, this is what I can see:
> Log.mappings
=> #<Elasticsearch::Model::Indexing::Mappings:0x007fcefd985368 @mapping={}, @options={:_ttl=>{:enabled=>true, :default=>"7d"}}, @type="log">
However, when using cURL, I can only the model properties and not the ttl option:
curl -XGET 'http://localhost:9200/logs/_mappings'
{
"logs": {
"mappings": {
"log": {
"properties": {
"created_at": {
"format": "dateOptionalTime",
"type": "date"
},
"id": {
"type": "long"
},
"operation": {
"type": "string"
},
"order_number": {
"type": "string"
},
"request_payload": {
"type": "string"
},
"response_payload": {
"type": "string"
},
"updated_at": {
"format": "dateOptionalTime",
"type": "date"
}
}
}
}
}
}
I've also tried to add the TTL option to the bulk import as an option (to achieve this: https://www.elastic.co/guide/en/elasticsearch/reference/1.4/docs-bulk.html#bulk-ttl) but I can't use that option:
> Log.import({
query: -> { where(id: ids) },
refresh: true,
return: 'errors',
ttl: '1d'
})
Unknown key: :ttl. Valid keys are: :start, :batch_size : {"ids":[358]}
Any idea on how I can do this?