本篇记录的全部是映射相关的操作: ### **新增** ### 命令: ### ``` curl -X PUT "http://10.10.16.180: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" } } } ' | json_pp ``` ### 结果 ### ``` { "acknowledged" : true } ``` ### **获取** ### 命令:`curl -X GET "http://10.10.16.180:9200/nba/_mapping" | json_pp` ### 结果: ``` gold@1498775ba8fe ~ % curl -X GET "http://10.10.16.180:9200/nba/_mapping" | json_pp % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 179 100 179 0 0 6618 0 --:--:-- --:--:-- --:--:-- 8950 { "nba" : { "mappings" : { "properties" : { "jerse_no" : { "type" : "keyword" }, "name" : { "type" : "text" }, "play_year" : { "type" : "keyword" }, "position" : { "type" : "keyword" }, "team_name" : { "type" : "text" } } } } } ``` ### **批量获取** ### 命令:`curl -X GET "http://10.10.16.180:9200/nba,cba/_mapping" | json_pp` ### 结果: ``` gold@1498775ba8fe ~ % curl -X GET "http://10.10.16.180:9200/nba,cba/_mapping" | json_pp % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 201 100 201 0 0 8355 0 --:--:-- --:--:-- --:--:-- 11166 { "cba" : { "mappings" : {} }, "nba" : { "mappings" : { "properties" : { "jerse_no" : { "type" : "keyword" }, "name" : { "type" : "text" }, "play_year" : { "type" : "keyword" }, "position" : { "type" : "keyword" }, "team_name" : { "type" : "text" } } } } } ``` ### **获取所有的索引的映射(方式一)** ### 命令:`curl -X GET "http://10.10.16.180:9200/_mapping" | json_pp` ### 结果: ``` gold@1498775ba8fe ~ % curl -X GET "http://10.10.16.180:9200/_mapping" | json_pp % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 201 100 201 0 0 12692 0 --:--:-- --:--:-- --:--:-- 20100 { "cba" : { "mappings" : {} }, "nba" : { "mappings" : { "properties" : { "jerse_no" : { "type" : "keyword" }, "name" : { "type" : "text" }, "play_year" : { "type" : "keyword" }, "position" : { "type" : "keyword" }, "team_name" : { "type" : "text" } } } } } ``` ### **获取所有的索引的映射(方式二)** ### 命令:`curl -X GET "http://10.10.16.180:9200/_all/_mapping" | json_pp` ### 结果: ``` gold@1498775ba8fe ~ % curl -X GET "http://10.10.16.180:9200/_all/_mapping" | json_pp % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 201 100 201 0 0 8011 0 --:--:-- --:--:-- --:--:-- 11166 { "cba" : { "mappings" : {} }, "nba" : { "mappings" : { "properties" : { "jerse_no" : { "type" : "keyword" }, "name" : { "type" : "text" }, "play_year" : { "type" : "keyword" }, "position" : { "type" : "keyword" }, "team_name" : { "type" : "text" } } } } } ``` ### **修改** ### 命令: ``` curl -X PUT "http://10.10.16.180:9200/nba/_mapping" -H 'Content-Type: application/json' -d' { "properties": { "Uname": { "type": "text" } } }' ``` ### 结果: ``` {"acknowledged":true} ``` ### Uname在mapping当中从来没存在过 实际上是在原有的基础上新增了Uname字段 ### ![](https://img.kancloud.cn/19/75/1975f182e17a1b8294723c2c7c680577_1669x550.png) ###