本篇记录的全部是索引的相关操作 ### **新增** ### 命令:`curl -X PUT "http://10.10.16.180:9200/nba" | json_pp` ### 结果: ### ``` gold@1498775ba8fe ~ % curl -X PUT "http://10.10.16.180:9200/nba" | json_pp % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 62 100 62 0 0 103 0 --:--:-- --:--:-- --:--:-- 104 { "acknowledged" : true, "index" : "nba", "shards_acknowledged" : true } ``` ### **获取** ### 命令:`curl -X GET "http://10.10.16.180:9200/nba" | json_pp` ### 结果: ### ``` gold@1498775ba8fe ~ % curl -X GET "http://10.10.16.180:9200/nba" | json_pp % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 225 100 225 0 0 9083 0 --:--:-- --:--:-- --:--:-- 12500 { "nba" : { "aliases" : {}, "mappings" : {}, "settings" : { "index" : { "creation_date" : "1694227082539", "number_of_replicas" : "1", "number_of_shards" : "1", "provided_name" : "nba", "uuid" : "8CLIFy9eS2qZcm-k3kFBpg", "version" : { "created" : "7020099" } } } } } ``` ### **删除** ### 命令:`curl -X DELETE "http://10.10.16.180:9200/nba" | json_pp` ### 结果: ``` gold@1498775ba8fe ~ % curl -X DELETE "http://10.10.16.180:9200/nba" | json_pp % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 21 100 21 0 0 153 0 --:--:-- --:--:-- --:--:-- 160 { "acknowledged" : true } ``` ### **批量获取** ### 命令:`curl -X GET "http://10.10.16.180:9200/nba,cba" | json_pp` ### 结果: ``` gold@1498775ba8fe ~ % curl -X GET "http://10.10.16.180:9200/nba,cba" | json_pp % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 449 100 449 0 0 19445 0 --:--:-- --:--:-- --:--:-- 26411 { "cba" : { "aliases" : {}, "mappings" : {}, "settings" : { "index" : { "creation_date" : "1694227737478", "number_of_replicas" : "1", "number_of_shards" : "1", "provided_name" : "cba", "uuid" : "Nhv8vckSSSKR7LcenSPVDA", "version" : { "created" : "7020099" } } } }, "nba" : { "aliases" : {}, "mappings" : {}, "settings" : { "index" : { "creation_date" : "1694227698390", "number_of_replicas" : "1", "number_of_shards" : "1", "provided_name" : "nba", "uuid" : "M6rRM4xFST64Nl24x51ZQg", "version" : { "created" : "7020099" } } } } } ``` ### **获取所有** ### 命令:`curl -X GET "http://10.10.16.180:9200/_all" | json_pp` ### 结果: ``` gold@1498775ba8fe ~ % curl -X GET "http://10.10.16.180:9200/_all" | json_pp % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 449 100 449 0 0 18398 0 --:--:-- --:--:-- --:--:-- 24944 { "cba" : { "aliases" : {}, "mappings" : {}, "settings" : { "index" : { "creation_date" : "1694227737478", "number_of_replicas" : "1", "number_of_shards" : "1", "provided_name" : "cba", "uuid" : "Nhv8vckSSSKR7LcenSPVDA", "version" : { "created" : "7020099" } } } }, "nba" : { "aliases" : {}, "mappings" : {}, "settings" : { "index" : { "creation_date" : "1694227698390", "number_of_replicas" : "1", "number_of_shards" : "1", "provided_name" : "nba", "uuid" : "M6rRM4xFST64Nl24x51ZQg", "version" : { "created" : "7020099" } } } } } ``` ### **获取es节点情况** ### 命令:`curl -X GET "http://10.10.16.180:9200/_cat/indices?v"` ### 结果: ``` gold@1498775ba8fe ~ % curl -X GET "http://10.10.16.180:9200/_cat/indices?v" health status index uuid pri rep docs.count docs.deleted store.size pri.store.size yellow open nba M6rRM4xFST64Nl24x51ZQg 1 1 0 0 230b 230b yellow open cba Nhv8vckSSSKR7LcenSPVDA 1 1 0 0 230b 230b ``` ### 返回的参数具体含义如下: > * `health`: 索引的健康状态,可以是以下几种状态之一: > * `green`: 所有主分片和副本分片都正常。 > * `yellow`: 所有主分片都正常,但是至少有一个副本分片丢失。 > * `red`: 至少有一个主分片丢失,索引无法正常工作。 > * `status`: 索引的状态,通常为`open`,表示索引是打开的并可用。 > * `index`: 索引的名称。 > * `uuid`: 索引的唯一标识符。 > * `pri`: 索引的主分片数量。 > * `rep`: 索引的副本分片数量。 > * `docs.count`: 索引中的文档数量。 > * `docs.deleted`: 被标记为删除的文档数量。 > * `store.size`: 索引在磁盘上的总存储大小。 > * `pri.store.size`: 主分片在磁盘上的存储大小。 > > 在给定的结果中,有两个索引被列出:`nba`和`cba`。它们都处于黄色状态,意味着它们的主分片和副本分片数量均为1,并且当前没有文档。存储大小为230字节,主分片的存储大小也是230字节。 ### 判断索引是否存在 ### 命令:`curl -I "http://10.10.16.180:9200/nba" ` ### 结果: ``` gold@1498775ba8fe ~ % curl -I "http://10.10.16.180:9200/nba" HTTP/1.1 200 OK content-type: application/json; charset=UTF-8 content-length: 225 ``` ### **关闭** ### 命令:`curl -X POST "http://10.10.16.180:9200/nba/_close" | json_pp` ### 结果: ``` gold@1498775ba8fe ~ % curl -X POST "http://10.10.16.180:9200/nba/_close" | json_pp % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 48 100 48 0 0 180 0 --:--:-- --:--:-- --:--:-- 184 { "acknowledged" : true, "shards_acknowledged" : true } ``` ### **打开** ### 命令:`curl -X POST "http://10.10.16.180:9200/nba/_open" | json_pp` ### 结果: ``` gold@1498775ba8fe ~ % curl -X POST "http://10.10.16.180:9200/nba/_open" | json_pp % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 48 100 48 0 0 111 0 --:--:-- --:--:-- --:--:-- 113 { "acknowledged" : true, "shards_acknowledged" : true } ``` ###