0. 索引分词概念
index:默认true,设置为false的话,那么这个字段就不会被索引
引用官文:https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index.html
index
The index option controls whether field values are indexed. It accepts true or false and defaults to true. Fields that are not indexed are not queryable.
1. 创建索引的同时创建mappings
PUT /index_str
{
"mappings": {
"properties": {
"realname": {
"type": "text",
"index": true
},
"username": {
"type": "keyword",
"index": false
}
}
}
}
2.查看分词效果
GET /index_mapping/_analyze
{
"field": "realname",
"text": "imooc is good"
}
3. 尝试修改
POST /index_str/_mapping
{
"properties": {
"name": {
"type": "long"
}
}
}
4. 为已存在的索引创建或创建mappings
POST /index_str/_mapping
{
"properties": {
"id": {
"type": "long"
},
"age": {
"type": "integer"
},
"nickname": {
"type": "keyword"
},
"money1": {
"type": "float"
},
"money2": {
"type": "double"
},
"sex": {
"type": "byte"
},
"score": {
"type": "short"
},
"is_teenager": {
"type": "boolean"
},
"birthday": {
"type": "date"
},
"relationship": {
"type": "object"
}
}
}