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
}
The crucial difference between them is that Elasticsearch will analyze the Text before it's stored into the Inverted Index while it won't analyze Keyword type. Analyzed or not analyzed will affect how it will behave when getting queried.
The keyword family includes the following field types: keyword , which is used for structured content such as IDs, email addresses, hostnames, status codes, zip codes, or tags. constant_keyword for keyword fields that always contain the same value.
It is not possible to update the mapping of an existing field. If the mapping is set to the wrong type, re-creating the index with updated mapping and re-indexing is the only option available. In version 7.0, Elasticsearch has deprecated the document type and the default document type is set to _doc.
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 :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With