Migrate field type from text to keyword on Elastic

2019-04-08 18:02发布

问题:

When I want to change the type of a field from text to keyword with this commande :

PUT indexStat/_mapping/StatCateg
{
  "StatCateg":{
    "properties": {
      "nom_categorie": {
        "type":"keyword","index": true
      }
    }
  }
}

I have this message :

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "mapper [nom_categorie] of different type, current_type [text], merged_type [keyword]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "mapper [nom_categorie] of different type, current_type [text], merged_type [keyword]"
  },
  "status": 400
}

回答1:

OK finaly i see in the doc that it's not possible to change data type of a field :

Updating existing mappings

Other than where documented, existing type and field mappings cannot be updated. Changing the mapping would mean invalidating already indexed documents. Instead, you should create a new index with the correct mappings and reindex your data into that index.

So the only solution is to :

  • Recreate a new index with good data types
  • Reindex the data with the Reindex API