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
相关推荐
学长毕设29 分钟前
基于SpringBoot非遗文化展示与传播平台设计与实现-附源码金銀銅鐵2 小时前
用 Swing 重做操作数栈演示琳少_2 小时前
java程序开发笔记叼烟扛炮4 小时前
[LangChain] 学习笔记(15):为什么你的重试没用——429、抖动、fallback 与熔断文丑颜不良啊5 小时前
LeetCode3401~3420题目解析wuyk5556 小时前
Spider-第20讲-综合实战可上线爬虫文丑颜不良啊6 小时前
LeetCode3421~3440题目解析code2cat7 小时前
【随笔】Java客户端选了HTTP/3,怎样知道请求实际走了哪个版本码云社区8 小时前
Java在线租房系统源码:VR看房素材、房源图片与内容维护方案码云社区9 小时前
Spring Boot智慧物业系统源码:合同到期提醒、续签资料与资产协作