Convert a string field to date in order to sort it

Hello!

I want to sort a field that happens to be a string. but the actual value of that string is date.
Is there any way to convert this field to date?

GET /index/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"product": "blah"
}
}
]
}
},
"sort": {
"string_date": {
"order": "desc"
}
}
}

Thank you!

/Angelos

Use a date datatype in your mapping.

Can I update the datatype?
For example from:

"string_date": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 100
}

to:

"string_date": {
"type": "date"
}

No. You need to reindex.

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