ElasticSearch 映射
官方文档: https://www.elastic.co/guide/en/elasticsearch/reference/7.x/mapping.html
上文说过了ElasticSearch的基本使用,本文来说说ElasticSearch的映射
映射是定义文档及其包含的字段如何存储和索引的过程
文档是字段的集合,一开始,我们都没为文档的字段设置类型,但是ES会自动为它决定类型
字段数据类型
https://www.elastic.co/guide/en/elasticsearch/reference/7.x/mapping-types.html
查看映射
未来ES可能会删除类型
查看映射就是查看索引下映射
GET /bank/_mapping
创建映射
创建新索引my-index并指定映射
PUT /my-index
{
"mappings": {
"properties": {
"age" : {
"type": "integer"
},
"name" : {
"type": "text"
},
"email" : {
"type" : "keyword"
}
}
}
}
添加新的映射
PUT /my-index/_mapping
{
"properties": {
"newMapping" :{
"type" : "keyword",
"index" : false
}
}
}
index为false 表示该字段不能被检索
修改映射与数据迁移
规定好映射后不允许修改映射
所以只能重新创建索引规定好映射再进行数据迁移
创建新索引
PUT /newbank
{
"mappings": {
"properties": {
"account_number": {
"type": "long"
},
"address": {
"type": "text"
},
"age": {
"type": "integer"
},
"balance": {
"type": "long"
},
"city": {
"type": "text"
},
"email": {
"type": "keyword"
},
"employer": {
"type": "text"
},
"firstname": {
"type": "text"
},
"gender": {
"type": "text"
},
"lastname": {
"type": "text"
},
"state": {
"type": "text"
}
}
}
}
数据传输
POST _reindex
{
"source": {
"index": "bank",
"type": "account"
},
"dest": {
"index" : "newbank"
}
}
查看
未使用类型后,类型默认为_doc
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。