Elasticsearch 是優秀的文檔數據庫,在咱們使用集羣方式建立咱們的文檔數據時,須要根據集羣node數量合理設置分片個數 從而提升數據查詢、讀取 效率;node
下面是分片設置塊數據庫
"settings": { "number_of_shards": 12,#分片個數,在建立索引不指定時 默認爲 5; "number_of_replicas": 1 #數據副本,通常設置爲1; },
下面是一個建立索引並設置分片的例子:json
curl -X PUT \ http://$1:9200/your_index_name/ \ -H 'content-type: application/json' \ -d '{ "settings": { "number_of_shards": 12, "number_of_replicas": 1 }, "mappings": { "sms_up": { "dynamic_templates": [ { "strings_as_keywords": { "match_mapping_type": "string", "mapping": { "type": "keyword" } } } ], "properties": { "account_id": { "type": "long" }, "date": { "type": "date", "format": "yyyy-MM-dd" }, "is_push_sms_up": { "type": "short" }, "mobile": { "type": "keyword" }, "push_sms_up_time": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss" }, "request_id": { "type": "keyword" }, "request_time": { "type": "date", "format": "epoch_second" }, "sms_account_primary": { "type": "integer" }, "sms_content": { "type": "keyword" }, "sms_exno": { "type": "keyword" }, "sms_facilitator_id": { "type": "integer" }, "sms_msgid": { "type": "keyword" }, "sms_sign_id": { "type": "integer" }, "sms_spno": { "type": "keyword" }, "sms_type": { "type": "long" }, "sms_up_rtime": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss" } } } } }'