当前位置:   article > 正文

ElasticSearch设置索引全局默认分片_elasticsearch 索引默认分片

elasticsearch 索引默认分片

设置全局分片数量:
put http://196.168.137.100:19085/_template/template_http_request_record
{
“index_patterns”: ["*"],
“settings”: {
“number_of_shards”: 5,
“number_of_replicas”: 1
}
}
指定创建索引时的分片数量:
put http://196.168.137.100:19085/<索引名称>
{
“settings”: {
“number_of_shards”: 12,
“number_of_replicas”: 1
}
}
client7.4.0创建索引时,指定主副分片

<dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-client</artifactId>
            <version>7.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.4.0</version>
        </dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

代码:

//创建索引
            CreateIndexRequest createIndexRequest = new CreateIndexRequest(“index”);
            //设置分片
            createIndexRequest.settings(
                    Settings.builder().put("index.number_of_shards", 5)
                            .put("index.number_of_replicas", 3));
            //同步响应
            CreateIndexResponse createIndexResponse = client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
            boolean acknowledged = createIndexResponse.isAcknowledged();
            boolean shardsAcknowledged = createIndexResponse.isShardsAcknowledged();
            if (acknowledged && shardsAcknowledged) {
                System.out.println(indexName + "索引创建成功");
            } else {
                throw new Exception("索引创建失败");
            }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/461190
推荐阅读
相关标签
  

闽ICP备14008679号