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
相关推荐
摇滚侠5 分钟前
elasticSearch是什么,如何使用,有什么用seventeennnnn7 分钟前
Java大厂面试真题:谢飞机的技术挑战wkj00117 分钟前
接口实现类向上转型和向上转型解析qqxhb18 分钟前
零基础设计模式——行为型模式 - 观察者模式寒士obj1 小时前
类加载的过程无名之逆1 小时前
大三自学笔记:探索Hyperlane框架的心路历程Chuck1sn1 小时前
我把 Cursor AI 整合到 Ruoyi 中,从此让 Java 脚手架脱离人工!广州山泉婚姻1 小时前
智慧零工平台后端开发进阶:Spring Boot 3结合MyBatis-Flex的技术实践与优化【无标题】水木石画室1 小时前
Spring Boot 常用注解面试题深度解析hweiyu001 小时前
tomcat指定使用的jdk版本