Mapping类似于数据库中的表定义,主要有以下几个作用:
- 定义索引中字段的名称
- 定义字段的数据类型,例如:字符串、数字…
- 倒排索引的相关配置,是否分词,字段分词器选择等
所有数据操作命令基于官方提供的样本测试数据,ES复杂操作的学习使用,需要样本数据看这里:官方样本数据
1.创建索引映射
PUT /my_index
{
"mappings": {
"properties": {
"age":{"type": "integer"},
"email":{"type": "keyword"},
"name":{"type": "text"}
}
}
}
2.已存在的映射添加新的映射字段
{
"properties":{
"employee-id":{
"type":"keyword",
"index":false
}
}
}
3.映射进行修改
不能直接修改索引的映射,如果必须要修改可以重新创建索引映射在进行数据转移
创建新的索引
PUT /new_bank
{
"mappings": {
"properties": {
"account_number": {
"type": "long"
},
"address": {
"type": "text"
},
"age": {
"type": "integer"
},
"balance": {
"type": "long"
},
"city": {
"type": "keyword"
},
"email": {
"type": "keyword"
},
"employer": {
"type": "keyword"
},
"firstname": {
"type": "text"
},
"gender": {
"type": "keyword"
},
"lastname": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"state": {
"type": "keyword"
}
}
}
}
4.迁移数据(旧索引迁移新索引),source-index是老索引,dest-index是新索引
POST _reindex
{
"source": {
"index": "bank",
"type": "account"
},
"dest": {
"index": "new_bank"
}
}