Elasticsearch 是優秀的文檔數據庫,在我們使用集群方式創建我們的文檔數據時,需要根據集群node數量合理設置分片個數 從而提高數據查詢、讀取 效率;
下面是分片設置塊
"settings": {
"number_of_shards": 12,#分片個數,在創建索引不指定時 默認為 5;
"number_of_replicas": 1 #數據副本,一般設置為1;
},
下面是一個創建索引並設置分片的例子:
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"
}
}
}
}
}'
