Elasticsearch In Action: Explicit Mapping

Excerpts are taken from my upcoming book: Elasticsearch in Action
Creating and updating schema using indexing and mapping APIs

Mapping using the indexing API

Creating a mapping definition during the creation
# Creating an employees schema upfront
PUT employees
{
"mappings":{
"properties": {
"name":{"type": "text"},
"age":{"type": "integer"},
"mmail":{"type": "keyword"},
"address":{
"properties":{
"street":{"type":"text"},
"country":{ "type":"text" }
}
}
}
}
}

Updating schema using the mapping API

# Additional data to the existing Employee document
{
"name":"John Smith",
"joining_date":"01-05-2021",
"phone_number":"01234567899"
...
}
# Updating the existing index with additional fields
PUT employees/_mapping
{
"properties":{
"joining_date":{
"type":"date",
"format":"dd-mm-yyyy"
},
"phone_number":{
"type":"keyword"
}
}
}

Updating an empty index

# Adding the mapping schema to an empty index
PUT departments/_mapping
{
"properties":{
"name":{
"type":"text"
}
}
}

Modifying the existing fields is not allowed

Reindexing data

# Migrating data to a new index with new schema
POST _reindex
{
“source”: {“index”: “orders”},
“dest”: {“index”: “orders_new”}
}

Aliases play an important role in migration

Type coercion

Elasticsearch in Action

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Madhusudhan Konda

Madhusudhan Konda

47 Followers

Madhusudhan Konda is a full-stack lead engineer, mentor, and conference speaker. He delivers live online training on Elasticsearch, Elastic Stack &Spring Cloud