0

I am trying to change the format of a string field in opensearch:

PUT my_index/_mapping
{
  "mappings": {
    "properties": {
      "timestamp": {
        "type": "date",
        "format": "YYYY-MM-DD HH:mm:ss.SSS"
      }
    }
  }
}

Response is

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "Root mapping definition has unsupported parameters:  [mappings : {properties={timestamp={format=YYYY-MM-DD HH:mm:ss.SSS, type=date}}}]"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Root mapping definition has unsupported parameters:  [mappings : {properties={timestamp={format=YYYY-MM-DD HH:mm:ss.SSS, type=date}}}]"
  },
  "status" : 400
}

I've spent days trying to figure this out, seems to me like Opensearch is just so unnecessarily complex.

naraghi
  • 430
  • 1
  • 6
  • 18

1 Answers1

1

You cannot change the type of an existing field once it's been created. You need to reindex your index with the wrong mapping into a new index with the right mapping.

First, create the new index:

PUT new_index
{
  "mappings": {
    "properties": {
      "timestamp": {
        "type": "date",
        "format": "YYYY-MM-DD HH:mm:ss.SSS"
      }
    }
  }
}

Then, reindex the old index into the new one

POST _reindex
{
  "source": {
    "index": "old_index"
  },
  "dest": {
    "index": "new_index"
  }
}
Val
  • 207,596
  • 13
  • 358
  • 360