defines structure of docs and how values are indexes
--> similar to schema in RDB
explicit mapping : defined by developer
dynamic mapping : auto generate field mapping
PUT /reviews
{
"mappings": {
"properties": {
"rating": {"type": "float"},
"content": {"type": "text"},
"product_id": {"type": "integer"},
"author": {
"properties": {
"first_name": {"type": "text"},
"last_name": {"type": "text"},
"email": {"type": "keyword"}
}
}
}
}
}
GET /reviews/_mapping
GET /reviews/_mapping/field/content
// for field in object
GET /reviews/_mapping/field/author.email
PUT /reviews
{
"mappings": {
"properties": {
"rating": {"type": "float"},
"content": {"type": "text"},
"product_id": {"type": "integer"},
"author.first_name": {"type": "text"}
"author.last_name": {"type": "text"}
"author.email": {"type": "keyboard"}
}
}
}
// add time stamp to reviews index
PUT /reviews/_mapping
{
"properties": {
"created_at": {"type": "date"}
}
}
epoch = 1/1/1970
PUT /reviews/_doc/3
{
"created_at": "2015-04-15T13:07:41Z"
}