Elasticsearch: Issues reindexing - ending up with more than one type

Viewed 318

ES 6.8.6 I am trying to reindex some indexes to reduce the number shards.

The original index had a type of 'auth' but recently I added a template that used _doc. When I tried:

curl -X POST "localhost:9200/_reindex?pretty" -H 'Content-Type: application/json' -d'
{
  "source": {
      "index": "auth_2019.03.02"
  },
  "dest": {
      "index": "auth_ri_2019.03.02",
      "type": "_doc"

  }
}
'

I get this error:

"Rejecting mapping update to [auth_ri_2019.03.02] as the final mapping would have more than 1 type: [_doc, auth]"

I understand that I can't have more than one type and that types are depreciated in 7.x. My question is can I change the type during the reindex operation.

I am trying to tidy everything up in preparation to moving to 7.x.

2 Answers

It looks like you have to write a script to change the document during the reindex process.

From the docs,

Like _update_by_query, _reindex supports a script that modifies the document.

You are indeed able to change type.

Think of the possibilities! Just be careful; you are able to change: _id, _type, _index, _version, _routing

For your case add


  "script": {
    "source": "ctx._type = '_doc'",
    "lang": "painless"
  }

Full example

{
  "source": {
      "index": "auth_2019.03.02"
  },
  "dest": {
      "index": "auth_ri_2019.03.02",
  },
  "script": {
    "source": "ctx._type = '_doc'",
    "lang": "painless"
  },
}

Firstly thanks to leandrojmp for prompting me to reread the docs and noticing the example where they had type specified for both source and dest.

I don't understand why but adding a type to the source specification solved the problem.

This worked:

curl -X POST "localhost:9200/_reindex?pretty" -H 'Content-Type: application/json' -d'
{
  "source": {
      "index": "auth_2019.03.02",
      "type": "auth"
  },
  "dest": {
      "index": "auth_ri_2019.03.02",
      "type": "_doc"

  }
}
'
Related