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
相关推荐
麦兜*几秒前
Spring Boot 启动过程全解析:从main方法到Tomcat启动的魔法之旅零度@8 分钟前
Java-Redis 缓存「从入门到黑科技」2026 版zzhongcy8 分钟前
多级缓存对比(Caffeine + Redis),以及缓存不一致问题的解决清晓粼溪9 分钟前
SpringCloud-05-Micrometer Tracing+ZipKin分布式链路追踪带刺的坐椅10 分钟前
灵动如画 —— 初识 Solon Graph Fluent API 编排cike_y12 分钟前
Spring整合Mybatis:dao层小股虫12 分钟前
缓存攻防战:在增长中台设计一套高效且安全的缓存体系小蒜学长14 分钟前
足球联赛管理系统(代码+数据库+LW)tkevinjd18 分钟前
IO流3(字符流)不吃香菜56719 分钟前
SpringBoot 与 SpringCloud用法和区别