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
相关推荐
秋天的怀念_David9 分钟前
第二十二夜 · 数字迷雾Raas10022 分钟前
AI网关部署方案?从部署到上线全流程niucloud-admin1 小时前
NIUCLOUD PHP SAAS上门家政使用文档:城市管理霸道流氓气质1 小时前
智能客服组件:分层意图识别、RAG Advisor 与人工转接状态机的 Vue3 + Spring AI 生产级实战captain3762 小时前
MyBatis操作数据库(入门2)心中有你02142 小时前
Java实现Dijkstra最短路径算法(邻接表 + 优先队列)步行cgn3 小时前
Spring MVC + Thymeleaf 模板解析失败:从 500 错误到页面正常显示lgcgkCQ3 小时前
【AI 转型实战 1】SpringAI 入门:搭建基础大模型对话能力Wang's Blog4 小时前
Java 项目实战:交友项目 - 用户体系集成总结学到老活到老4 小时前
第 24 集:配置文件写了 80,Spring Boot 为什么读到 90?