Create mapping
PUT profile
{
"mappings": {
"doc": {
"properties": {
"name": { "type": "text" },
"age": { "type": "integer" }
}
}
}
}
Check mapping
GET profile/_mapping
Create documents to test
POST profile/doc/1
{
"name": "Marcelo",
"age": 31
}
POST profile/doc/2
{
"name": "john",
"age": 25
}
Update the index mapping
PUT profile/_mapping/doc
{
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"age": { "type": "integer" }
}
}
Check the new mapping for index
GET profile/_mapping
Create new document:
POST profile/doc/3
{
"name": "novo usuario",
"age": 40
}
This query should return user 3 because this document was create using a new mapping that make possible to query by keyword:
GET profile/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"name.keyword": "novo usuario"
}
}
]
}
}
}
This query should no find user 1 because it was created when mapping does not have support to keyword for name:
GET profile/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"name.keyword": "marcelo"
}
}
]
}
}
}