Elastic Search Mapping
You can add a mapping to existing index with PUT API
You may define multiple mappings for a given index. However if the mapping has the same fields they map to the same field internally.
Create a mapping :
Mapping is similar to a schema in relational DB.This command create a mapping for the index - test_index and type - test_type.
Dynamic - strict specify there are strict checks. Any new field added it will throw an exception.
PUT test_index
{
"mappings": {
"test_type": {
"dynamic": "strict",
"properties": {
"car_number": {
"type": "string"
},
"manufacturer": {
"type": "string"
}
}
}
}
}
Edit an existing mapping -
Adding a new field to an existing type. Suppose you want to add the car model to the test_type.This will fail as dynamic : strict is set in the mapping.
In order to edit the mapping :
PUT test_index/_mapping/test_type { "properties": { "car_model": { "type": "string" } } }
Get a mapping -
For very large json objects it may be simple to create a mapping by inserting an entry into the a type and then extract the mapping using the below command.GET /test_index
/_mapping/test_type
Comments
Post a Comment