Sathish22
(Sathish Thumma)
January 12, 2021, 4:10am
1
Hi All,
We have created an index that consists of text data type for all fields, but we need to convert timestamp field from text to date (format "2021-01-12 09:19:25.890") but unable to do.
I have tried creating a new index with the correct data type as below
PUT /index-0002
{
"settings" : {
"number_of_shards" : 4,
"number_of_replicas" : 1
},
"mappings" : {
"properties" : {
"filed1" : { "type" : "long"},
"filed2" : { "type" : "text" },
"filed3" : { "type" : "text" },
"filed4": { "type" : "text" },
"timestamp": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss.SSS"
}
}
}
}
migrated data from old to new index using reindex API
POST /_reindex
{
"source": {
"index": "index-0001"
},
"dest": {
"index": "index-0002"
}
}
but once it is done the index data type changed to text instead of date
Please help me resolve this issue.
warkolm
(Mark Walkom)
January 12, 2021, 5:13am
2
Welcome to our community!
What is the mapping of the index-0001
index?
Sathish22
(Sathish Thumma)
January 12, 2021, 5:26am
3
Thank you for quick response
mapping for index-0001
"mappings" : {
"properties" : {
"filed1" : { "type" : "text"},
"filed2" : { "type" : "text" },
"filed3" : { "type" : "text" },
"filed4": { "type" : "text" },
"timestamp": { "type" : "text" }
}
}
warkolm
(Mark Walkom)
January 12, 2021, 6:31am
4
Can you post an example document as well please.
Sathish22
(Sathish Thumma)
January 12, 2021, 6:54am
5
Document Example
{
"_index" : "index-0001",
"_type" : "_doc",
"_id" : "rE64RXYBWfNr3RkH119n",
"_version" : 1,
"_seq_no" : 240,
"_primary_term" : 1,
"found" : true,
"_source" : {
"filed1" : "7",
"filed2" : "info",
"filed3" : "Source exception",
"filed4" : "Exiting ",
"timestamp" : "2020-12-09 03:32:59.830"
}
}
warkolm
(Mark Walkom)
January 12, 2021, 7:00am
6
It'd help if you could please format your code/logs/config using the </>
button, or markdown style back ticks. It helps to make things easy to read which helps us help you
Sathish22
(Sathish Thumma)
January 13, 2021, 8:27am
7
PFB details
new index with the correct data type as below
PUT /index-0002
{
"settings":{
"number_of_shards":4,
"number_of_replicas":1
},
"mappings":{
"properties":{
"filed1":{
"type":"long"
},
"filed2":{
"type":"text"
},
"filed3":{
"type":"text"
},
"filed4":{
"type":"text"
},
"timestamp":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss.SSS"
}
}
}
}
migrated data from old to new index using reindex API
POST /_reindex
{
"source":{
"index":"index-0001"
},
"dest":{
"index":"index-0002"
}
}
index-0001 mapping
"mappings":{
"properties":{
"filed1":{
"type":"text"
},
"filed2":{
"type":"text"
},
"filed3":{
"type":"text"
},
"filed4":{
"type":"text"
},
"timestamp":{
"type":"text"
}
}
}
Document Example
{
"_index":"index-0001",
"_type":"_doc",
"_id":"rE64RXYBWfNr3RkH119n",
"_version":1,
"_seq_no":240,
"_primary_term":1,
"found":true,
"_source":{
"filed1":"7",
"filed2":"info",
"filed3":"Source exception",
"filed4":"Exiting ",
"timestamp":"2020-12-09 03:32:59.830"
}
}
That looks fine and the new index has the correct mapping. You should now be able to delete the old index. I assume this solves the problem?
Sathish22
(Sathish Thumma)
January 13, 2021, 9:48am
9
But after executing reindex API, in the new Index, timestamp field data type is text instead of date data type
warkolm
(Mark Walkom)
January 13, 2021, 9:26pm
10
Sathish22:
index-0002
I don't believe you have posted the mapping for that, just what you used as a template. If you can post the mapping it should make things clearer.
Sathish22
(Sathish Thumma)
January 15, 2021, 6:08am
11
index-0002 mapping
"mappings":{
"properties":{
"filed1":{
"type":"long"
},
"filed2":{
"type":"text"
},
"filed3":{
"type":"text"
},
"filed4":{
"type":"text"
},
"timestamp":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss.SSS"
}
}
}
system
(system)
Closed
February 12, 2021, 6:08am
12
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.