PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 24, 2022

[FIXED] How to reindex and change _type

 October 24, 2022     elasticsearch, reindex     No comments   

Issue

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.


Solution

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


Answered By - jaspreet chahal
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing