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

 

转载于:https://www.cnblogs.com/tank1992/p/10906840.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值