ElasticSearch映射关系(mapping)常用数据类型:keyword、boolean、text、integer、long等。详细数据类型参考官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/7.9/mapping.htmlElasticSearch中所有存储的字段都被放在了映射关系中创建索引后,可以预选设置所有的字段映射关系,如果不设置,创建文档的时候会根据每个字段值自动匹配映射关系官方文档:https://www.elastic.co/cn/ 常用操作 》创建映射关系
相当于MySQL中的建表,但是创建文档的时候未创建的字段也会被追加进来
注意:创建映射关系前需要先创建好索引
请求格式:/<索引名称>/_mapping
请求示例
请求方式:PUT
发送请求:
curl -X PUT http://192.168.3.201:9200/user001/_mapping -H 'Content-Type:application/json' -d'
{
"properties": {
"id": {
"type": "long",
"index": true
},
"name": {
"type": "keyword",
"index": true
},
"age": {
"type": "long",
"index": true
},
"sex": {
"type": "long",
"index": true
},
"tel": {
"type": "keyword",
"index": true
},
"address": {
"type": "text",
"index": false
}
}
}'
说明:index关键字表示指明该字段是否创建索引,默认true
响应结果:
{
"acknowledged": true
}
》查询映射关系
相当于MySQL中的查看表结构
请求格式:/<索引名称>/_mapping
请求示例
请求方式:GET
发送请求:
curl -X GET http://192.168.3.201:9200/user001/_mapping
响应结果:
{
"user001": {
"mappings": {
"properties": {
"address": {
"type": "text",
"index": false
},
"age": {
"type": "long"
},
"id": {
"type": "long"
},
"name": {
"type": "keyword"
},
"sex": {
"type": "long"
},
"tel": {
"type": "keyword"
}
}
}
}
}



