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

猜你喜欢

转载自www.cnblogs.com/tank1992/p/10906840.html