Remapping an index

I've followed is guide in an attempt to apply a new (reduced) mapping to an existing index :

I realise that this is a very old blog post. The "atomic" step which is said to re-index , doesn't seem to index any documents.

I've tried creating a new index with the reduced mappings and using the _reindex endpoint to copy over documents, but this seems to overwrite the mapping that I have added to the new index with the mappings from the original index.

Am I missing something (obvious)?

Yea, you are correct in using _reindex API as that is required to reindex documents from old to new index. However, if your new index has reduced mapping, in other words, fields "missing", mapping for missing fields is added automatically as default.
To get around this, you may choose to selectively reindex fields. Check this out ... https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#docs-reindex-filter-source

As an example ... the following worked for me ...

PUT test_firstname_lastname
{
  "mappings" : {
    "document" : {
      "properties" : {
        "first" : {
            "type" : "text"
          },
        "last" : {
            "type" : "text"
          }
      }
    }
}
}

PUT test_firstname_lastname/document/1
{
  "first":"John",
  "last":"Doe"
}

GET test_firstname_lastname/_search

PUT test_firstname
{
  "mappings" : {
    "document" : {
      "properties" : {
        "first" : {
            "type" : "text"
          }
      }
    }
}
}

POST _reindex
{
  "source": {
    "index": "test_firstname_lastname",
    "_source": ["first"]
  },
  "dest": {
    "index": "test_firstname"
  }
}

GET test_firstname/_mapping
GET test_firstname/_search

Thanks for the answer Jaspreeet.

Turned out that this as me misunderstanding elasticsearch basics. I was confusing the _source property of a doc with the mapping of an index.

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