您能夠經過 Elasticsearch 的 RESTFul API 來建立索引:app
PUT http://127.0.0.1:9200/commodity
注意:默認狀況下,建立的索引分片數量是 5 個,副本數量是 1 個。curl
您能夠經過以下參數來指定分片數、副本數量:ide
{ "settings": { "number_of_shards": 3, "number_of_replicas": 2 } }
經過 CURL 命令來上手操做一下,咱們嘗試建立一個商品索引, 看下效果:工具
curl -X PUT "localhost:9200/commodity?pretty"
索引建立成功會返回如下出參:url
{ "acknowledged" : true, "shards_acknowledged" : true, "index" : "commodity"}
以下圖所示:3d
其實,咱們能夠在建立索引的時候,同時將索引的類型、以及映射一併建立好:code
curl -X PUT "localhost:9200/commodity?pretty"
入參:blog
{ "settings": { "number_of_shards": 3, "number_of_replicas": 2 }, "mapping": { "_doc": { "properties": { "commodity_id": { "type": "long" }, "commodity_name": { "type": "text" }, "picture_url": { "type": "keyword" }, "price": { "type": "double" } } } } }
咱們建立了一個分片數爲 3,副本數爲 2 的索引,同時,定義了一個 _doc
的類型,裏面包含了 4 個字段,類型各不相同。索引
接下來,咱們用 Postman 工具來一次性建立帶有類型、映射的索引(Index):it
這裏應爲筆者經過 CURL 建立索引,因爲帶入參,出現了格式錯誤的問題,改用了 Postman 工具,效果相同。
咱們能夠經過以下 API 來修改索引的副本數:
PUT http://127.0.0.1:9200/commodity/_settings
入參:
{ "number_of_replicas": 3}
咱們將 commodity
索引副本數更新爲了 3: