映射的介绍和使用
在上一章介绍了索引的使用,这一章我们来简单介绍 一下 映射,有兴趣的可以参考一下: elasticSearch核心概念的介绍(一):基本介绍和索引的基本使用
-
新增
- 请求
curl -X PUT "http://172.25.45.150:9200/nba/_mapping" -H 'Content-Type:application/json' -d ' { "properties":{ "name":{ "type":"text" }, "team_name":{ "type":"text" }, "position":{ "type":"keyword" }, "play_year":{ "type":"keyword" }, "jerse_no":{ "type":"keyword" } } } '
-
响应
{ "acknowledged": true }
-
获取索引mapping
-
请求
curl -X GET "http://172.25.45.150:9200/nba/_mapping"
-
响应
{ "nba": { "mappings": { "properties": { "jerse_no": { "type": "keyword" }, "name": { "type": "text" }, "play_year": { "type": "keyword" }, "position": { "type": "keyword" }, "team_name": { "type": "text" } } } } }
-
-
获取所有mapping
-
请求
curl -X GET "http://172.25.45.150:9200/_mapping"
-
-
修改mapping
需要注意的是es规定了我们可以对mapping进行新增字段,但是我们无法进行字段类型的修改。例如把某一个字段的type=text修改成type=keyword,如需要修改,我们只能重新创建索引。
-
请求
curl -X POST "http://172.25.45.150:9200/nba/_mapping" -H 'Content-Type:application/json' -d ' { "properties":{ "name":{ "type":"text" }, "team_name":{ "type":"text" }, "position":{ "type":"keyword" }, "play_year":{ "type":"keyword" }, "jerse_no":{ "type":"keyword" }, "contry":{ "type":"keyword" } } } '
-
响应
{ "acknowledged": true }
-
- text : 表示字段是使用全文索引,可以进行分词,例如 ”我是一名学生“ 他会被分成 我、是、学生 等。
- keyword:表示是一个关键字,不会被分词。