Adding Mappings
Now we are going to add a mapping to our ecommerce index. To do that, we are first going to remove the index and add it once again with the mapping. The reason why we are doing this, is that if you have data in an index, then you need to create a new index and add the data to it. If the index has no data, then there is no need to remove the index first.
DELETE /ecommerce
Now that the index has been removed, let’s create it again, but this time with mappings.
PUT /ecommerce
{
"mappings": {
"product": {
"properties": {
"name": {
"type": "string"
},
"price": {
"type": "double"
},
"description": {
"type": "string"
},
"status": {
"type": "string"
},
"quantity": {
"type": "integer"
},
"categories": {
"type": "nested",
"properties": {
"name": {
"type": "string"
}
}
},
"tags": {
"type": "string"
}
}
}
}
}
As you can see, mapping information is nested within a mapping property, where the product property is the name of the mapping type, which then contains its mapping information. Arrays are automatically detected in the JSON, so mapping fields as strings will support a string array.
That’s it! It is as easy as that to create an index with mapping information.
Here is what you will learn:
- The architecture of Elasticsearch
- Mappings and analyzers
- Many kinds of search queries (simple and advanced alike)
- Aggregations, stemming, auto-completion, pagination, filters, fuzzy searches, etc.
- ... and much more!