elasticsearch索引分片扩容操作手册

elasticsearch索引分片扩容操作手册

解决方案goocz2025-06-12 11:31:387A+A-

操作步骤

  1. 创建具有满足要求分片数的新索引
  2. Reindex旧索引到新索引
  3. 删除旧索引
  4. 新索引创建旧索引别名

实际操作命令

1、创建具有满足要求分片数的新索引

(1)创建满足数据格式要求及分片要求的索引模板

{

"order": 0,

"index_patterns": [

"ts_kv*"

],

"settings": {

"index": {

"number_of_shards": "9",

"number_of_replicas": "0",

"refresh_interval": "-1"

}

},

"mappings": {

"properties": {

"@timestamp": {

"type": "date"

},

"entity_type": {

"type": "text",

"fields": {

"keyword": {

"ignore_above": 256,

"type": "keyword"

}

}

},

"str_v": {

"type": "text",

"fields": {

"keyword": {

"ignore_above": 256,

"type": "keyword"

}

}

},

"@version": {

"type": "text",

"fields": {

"keyword": {

"ignore_above": 256,

"type": "keyword"

}

}

},

"long_v": {

"type": "long"

},

"entity_id": {

"type": "text",

"fields": {

"keyword": {

"ignore_above": 256,

"type": "keyword"

}

}

},

"key": {

"type": "text",

"fields": {

"keyword": {

"ignore_above": 256,

"type": "keyword"

}

}

},

"ts": {

"type": "date"

}

}

},

"aliases": {}

}

1)注意事项:副本暂时设置为0及禁止刷新

2)采用cerebro工具创建索引模板

3)采用http API创建索引模板

curl -XPUT http://bigdata-1:9200/_template/ts_kv_template -d '@/path/to/your/ts_kv_templatel.json'

创建新索引

通过cerebro工具创建索引

注意:

  • 填写索引名称即可。
  • 分片和副本可以按要求设置,也可以不设置。若不设置,则会根据索引模板来,如果这里设置则会根据这里的设置来
  • Setting可将template中的设置拷贝过来,也可不设置。不设置则会根据索引模板来。

通过rest api创建索引

PUT http://bigdata-1:9200/index_name

注意:默认情况下,创建的索引分片数量是 5 个,副本数量是 1 个。

您可以通过如下参数来指定分片数、副本数量:

{

"settings": {

"number_of_shards": 3,

"number_of_replicas": 2

}

}

Reindex旧索引到新索引

POST /_reindex?slices=9&refresh

{

"source": {

"index": "product",

"size": 10000

},

"dest": {

"index": "product1"

}

}

注意:slices=9&refresh慎用,slices数量最好和分片数据相同,默认就是分片数

"size": 10000大小谨慎设置,根据集群规模及性能设置,默认1000一般足够

删除旧索引

删除索引的方式很多,在此不再赘述。

新索引创建旧索引别名

POST /_aliases

{

{

"actions" : [

{ "add" : { "index" : "index_name", "alias" : "alias_name" } }

]

}

}

点击这里复制本文地址 以上内容由goocz整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!

果子教程网 © All Rights Reserved.  蜀ICP备2024111239号-5