索引是具有相同結構的文檔集合.例如,可以有一個客戶的索引,包括一個產品目錄的索引,一個訂單數據的索引等.
創建索引時,默認情況下,分片的數量是5個,副本的數量是1個.
創建索引
例如:創建三個主分片,兩個副本分片
請求:PUT http:127.0.0.1:9200/test
參數:
{
"settings":{
"index":{"number_of_shards":3,"number_of_replicas":2}
}
}
返回值:
{
"acknowledged": true,
"shards_acknowledged": true
}
如圖,我用的是Postman可視化個工具創建的
image.png
訪問請求,如圖:
image.png
索引創建成功
修改索引
修改副本的數量為1
請求:PUT http:127.0.0.1:9200/test/_settings
參數:
{
"settings":{
"number_of_replicas":1
}
}
返回值:
{
"acknowledged": true
}
訪問請求,如圖:
image.png
刪除索引
請求:DELETE http:127.0.0.1:9200/test
返回值:
{
"acknowledged": true
}
獲取索引
請求:GET http:127.0.0.1:9200/test
返回值(返回索引的詳細信息):
{
"test": {
"aliases": {},
"mappings": {},
"settings": {
"index": {
"creation_date": "1560310766588",
"number_of_shards": "3",
"number_of_replicas": "2",
"uuid": "GV4OolBbTVWRjbNGOIIfOw",
"version": {
"created": "5040099"
},
"provided_name": "test"
}
}
}
}
刪除索引
請求:DELETE http:127.0.0.1:9200/test
返回值:
{
"acknowledged": true
}
關閉索引
關閉的索引會繼續占用磁盤空間而不能使用,所以關閉索引接口可能造成磁盤空間的浪費,禁止使用關閉索引功能,可以設置config/elasticsearch.yml 文件 settingscluster.indices.close.enable為false
,默認的是true.
請求:POST127.0.0.1:9200/test/_close
返回值:
{
"acknowledged": true
}
打開索引
請求:POST127.0.0.1:9200/test/_open
返回值:
{
"acknowledged": true
}