Reputation: 6921
I index my couchbase documents in elasticsearch (using xdcr). In couchbase, we have fields storing unix timestamps, but I want to index them as date-time in ElasticSearch. Is there a way to tell elasticsearch to convert unix timestamp (in seconds) to date time?
thanks.
Upvotes: 1
Views: 7035
Reputation: 36
Transform function in mapping is deprecated since elasticsearch 2.0 due to debugging issues. The solution might be this:
Create a new mapping with updated type (you can get that copy pasted from you current mapping using GET your_index/_mapping). Update you date_created type to "epoch_second"
PUT index2
{
"mappings": {
"couchbaseDocument": {
"properties": {
"doc" : {
"properties" : {
"createdAt" : {"type" : "date","format":"epoch_second"},
"amount": {
"type": "float"
},
"appGroup": {
"type": "long"
},
"bmi": {
"type": "float"
},
Use that mapping to reindex from your current index(use script if need to convert data) :
POST _reindex
{
"source": {
"index": "index1"
},
"dest": {
"index": "index2"
},
"script": {
"lang": "painless",
"inline": "if(ctx._source.doc.createdAt !=null){ ctx._source.doc.createdAt = (long)ctx._source.doc.createdAt}"
}
}
Upvotes: 0
Reputation: 6921
no one answered, so I continued googling and found the answer here:
{
"test" : {
"transform" : {
"script" : "ctx._source['date_created'] = ctx._source['date_created'].toLong() * 1000",
"lang": "groovy"
},
"properties" : {
"date_created" : {"type" : "date"},
}
}
}
Upvotes: 4