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
相关推荐
Mr数据杨3 分钟前
【Codex】用学生支持周报模块跟踪个性化支持进展JavaPub-rodert10 分钟前
Apache Jena 详解:Java 开发者如何真正搭起一套知识图谱与语义服务lhldsg17 分钟前
线上住宿预约系统开发实战:从需求分析到接口设计剑指offer.41 分钟前
Linux多任务-线程篇2601_9620639743 分钟前
Spring Boot拦截器(Interceptor)详解这是程序猿1 小时前
深入剖析Java HashMap:底层原理、数据结构与核心机制全解析不才不才不不才1 小时前
Spring 源码系列(25): @EnableTransactionManagement 与 TransactionInterceptor隔窗听雨眠1 小时前
CI/CD测试数据清理完全指南:从污染根因到三层清理覆盖的完整方案MetaLite1 小时前
Spring-Scheduled多实例重复执行怎么办-Redis分布式锁如何只让一个节点运行Query*1 小时前
Agent 开发之项目 AI 能力自我进化:通过浏览器自动化与数据采集实现持续学习