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
相关推荐
今天又在写代码4 小时前
java-v2competes5 小时前
慈善基金投资底层逻辑应用 顶层代码低代码配置平台开发结构方式数据存储模块2501_913061346 小时前
网络原理知识希望永不加班6 小时前
Spring AOP 代理模式:CGLIB 与 JDK 动态代理区别flushmeteor7 小时前
java的动态代理和字节码生成技术eggwyw7 小时前
基于SpringBoot和PostGIS的云南与缅甸的千里边境线实战0xDevNull7 小时前
MySQL 别名(Alias)指南:从入门到避坑lv__pf7 小时前
springboot原理java1234_小锋7 小时前
Java高频面试题:什么是可重入锁?饭后一颗花生米7 小时前
Git冷命令拯救崩溃现场