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
相关推荐
奋斗者1号2 分钟前
解决Git Push Gerrit分支失败的全流程实战tsyjjOvO2 分钟前
SpringMVC 从入门到精通(续)Binary-Jeff2 分钟前
MySQL MVCC 原理解析:Undo Log、ReadView 与版本可见性机制于先生吖6 分钟前
基于 Java 开发短剧系统:完整架构与核心功能实现badhope8 分钟前
GitHub超有用项目推荐:skill仓库--用技能树打造AI超频引擎一只鹿鹿鹿9 分钟前
网络安全风险评估报告如何写?(Word文件)逆境不可逃10 分钟前
【后端新手谈 04】Spring 依赖注入所有方式 + 构造器注入成官方推荐的原因Anastasiozzzz11 分钟前
深度解析 Java 单例模式NGC_661113 分钟前
G1收集器森林里的程序猿猿15 分钟前
垃圾收集器ParNew&CMS与底层标记三色标记算法