How to reindex a Index with new data field types?

Hi, I'm trying to change a field type to another type, I've seem that I cannot do that directly in my current Index, so I'm trying to use the REINDEX API.

I've tried something like this, I know it's wrong, but it's just to show my idea.

POST _reindex
{
  "source": {
    "index": "auto_de_infracao"
  },
  "dest": {
    "index": "auto_de_infracao2"
  },
  "script": {
    "lang": "painless",
    "inline": "ctx._source.valAutoInfracao = ctx._source.valAutoInfracaoX",
    "type":"number"
  }
}

Objective change valAutoInfracao type to number

Hey there, you can change your mappings with a two-step process:

  1. Create the destination index with the mappings you want, e.g. valAutoInfracao is a number.
  2. Reindex data from the source index into the destination index.

As documents are indexed into the destination index, they'll be mapped with the mapping you've specified on that index. See https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html#_updating_existing_field_mappings for more info.

Thanks,
CJ

3 Likes

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