private void createIndex(String indexName) {
IndexCoordinates indexCoordinates = IndexCoordinates.of(indexName);
IndexOperations indexOperations = elasticsearchRestTemplate.indexOps(indexCoordinates);
//设置主分片数、副本数、refresh刷新时间间隔
Map<String, String> setting = new MapBuilder<String, String>()
.put("index.number_of_shards", "3")
.put("index.number_of_replicas", "3")
.put("index.refresh_interval", "1s").map();
//创建索引,并设置settings参数
indexOperations.create(Document.from(setting));
//创建索引mapping方案1:指定以Message类为mapping模板
indexOperations.putMapping(indexOperations.createMapping(Message.class));
/* //创建索引mapping方案2:json字符串形式
String mappingJson = "{\n" +
" \"properties\": {\n" +
" \"field1\": { \"type\": \"text\" },\n" +
" \"field2\": { \"type\": \"keyword\" }\n" +
" }\n" +
"}";
indexOperations.putMapping(Document.parse(mappingJson));*/
}
spring-data-elasticsearch 使用java api进行动态创建索引
秋楓_Lance2024-03-08 21:33
相关推荐
MSTcheng.8 小时前
【C++】C++异常大模型玩家七七9 小时前
基于语义切分 vs 基于结构切分的实际差异Coder_Boy_10 小时前
技术发展的核心规律是「加法打底,减法优化,重构平衡」寻星探路14 小时前
【深度长文】万字攻克网络原理:从 HTTP 报文解构到 HTTPS 终极加密逻辑曹牧16 小时前
Spring Boot:如何测试Java Controller中的POST请求?爬山算法17 小时前
Hibernate(90)如何在故障注入测试中使用Hibernate?kfyty72517 小时前
集成 spring-ai 2.x 实践中遇到的一些问题及解决方案猫头虎17 小时前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题李少兄17 小时前
在 IntelliJ IDEA 中修改 Git 远程仓库地址