1. 程式人生 > >ES 建立索引設定(setting)基礎

ES 建立索引設定(setting)基礎

1.建立索引

PUT /my_index
{
    "settings": { ... any settings ... },
    "mappings": {
        "type_one": { ... any mappings ... },
        "type_two": { ... any mappings ... },
        ...
    }
}

如果你想禁止自動建立索引,你 可以通過在 config/elasticsearch.yml 的每個節點下新增下面的配置:
action.auto_create_index: false

2.索引設定

   索引設定分為static

dynamic,

static They can only be set at index creation time or on a closed index. dynamic They can be changed on a live index using the update-index-settings API. 修改分片和副本數:
PUT  /my_index
{
   "number_of_replicas":0,
   "number_of_shards":1

}

動態設定:

PUT  /my_index/_settings  
{  
    "index" : {
   "number_of_replicas":0
    }
} 


2.1 建立my_index 索引

使用預設配置:

POST /my_index/products/_bulk
{ "index": { "_id": 1 }}
{ "price" : 10, "productID" : "XHDK-A-1293-#fJ3" }
{ "index": { "_id": 2 }}
{ "price" : 20, "productID" : "KDKE-B-9947-#kL5" }
{ "index": { "_id": 3 }}
{ "price" : 30, "productID" : "JODL-X-1937-#pV7" }
{ "index": { "_id": 4 }}
{ "price" : 30, "productID" : "QQPX-R-3956-#aD8" }

檢視該索引的設定: 5個分片,一個副本

GET /my_index/_settings
{
   "my_index": {
      "settings": {
         "index": {
            "creation_date": "1507996404894",
            "number_of_shards": "5",
            "number_of_replicas": "1",
            "uuid": "q3xU7mMKTUKmqEq4FUsswA",
            "version": {
               "created": "5050199"
            },
            "provided_name": "my_index"
         }
      }
   }
}
head 檢視如下:



修改副本數量:(分片數不能動態修改)

PUT /my_index/_settings
{
     "number_of_replicas":0
}

----------------------
{
   "acknowledged": true
}

副本刪除了:



一次修改所有的索引副本數量:(強迫症,自己的虛擬機器本來是2個節點的叢集的,但每次只啟動一臺,所以建索引都是按照預設2個副本,不想你改配置,所以,又不想再head 上看到黃色的標識!!用下面全部修改下,線上環境慎用!)

PUT /_all/_settings
{
    "index": {"number_of_replicas":0}
     
}