Elasticsearch在創建索引時指定主分片個數


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"
          }
        }
      }
    }
}'

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM