Home > Net >  How to reindex and change _type
How to reindex and change _type

Time:10-14

We need to migrate a number of indexes from ElasticSearch 6.8 to ElasticSearch 7.x. To be able to do this, we now need to go back and fix a large number of documents are the _type field of these documents aren't _doc as required. We fixed this for newer indexes, but some of the older data which we still need has other values in here.

How do we reindex these indexes and also change the _type field?

POST /_reindex
{
    "source": {
        "index": "my-index-2021-11"
    },
    "dest": {
        "index": "my-index-2021-11-n"
    },
    "script": {
      "source": "ctx._type = '_doc';"
    }
}

I saw a post indicating the above might work, but on execution, the value for _type in the next index was still the existing of my-index.

The one option I can think of is to iterate through each document in the index and add it to the new index again which should create the correct _type, but that will take days to complete, so not so keen on doing that.

CodePudding user response:

I think below should work . Please test it out, before running on actual data

{
    "source": {
        "index": "my-index-2021-11"
    },
    "dest": {
        "index": "my-index-2021-11-n",
        "type":"_doc"
    }
}

Docs to help in upgradation

  1. https://www.elastic.co/guide/en/elasticsearch/reference/7.17/reindex-upgrade-inplace.html
  • Related