Problem:
Need to view existing mappings for an index. Need to add mappings to existing mappings. Update mappings for existing fields.
Solution Summary:
We can use _mapping endpoint to see current mappings.
Prerequisites:
Working elasticsearch cluster and Kibana.
Solution Steps:
Initial Test Data
You may create an index employee with a document if you are not following along:
PUT /employee/_doc/1?pretty
{
"name": "Heartin",
"salary": 10000000
}
Viewing current mappings
GET employee/_doc/_mapping
Response:
{
"employee": {
"mappings": {
"_doc": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"salary": {
"type": "long"
}
}
}
}
}
}
Adding New Mappings
PUT employee/_doc/_mapping
{
"properties": {
"certifications": {
"type": "integer"
}
}
}
Updating Existing Mappings
Try changing the type for Salary to "double" from "float".
PUT employee/_doc/_mapping
{
"properties": {
"salary": {
"type": "double"
}
}
}
Error Response:
...
{
"type": "illegal_argument_exception",
"reason": "mapper [salary] cannot be changed from type [long] to [double]"
}...
Note: You cannot change existing mappings. May delete index and reindex. However, you can add additional mappings to existing fields (E.g. adding a keyword type to a text field).
TODO
- Create an index with a text field. Add a keyword type to that text field.
Recent comments