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
相关推荐
老板一杯拿铁2 分钟前
Java 八股文面试详解:从基础到进阶的全面梳理const_qiu3 分钟前
第 2.5 章 2.5.4-2.5.5:JWT 双 Token 与声明式权限守卫bug菌5 分钟前
一个周末就想把短链服务推到 10 万 QPS,真能靠加 Redis 做到吗?撸串-研究生5 分钟前
springboot福利院管理系统73979不得了zz1 小时前
04-Spring AI Alibaba ReactAgent 生产级实践:工具调用、结构化输出、HITL 与上下文管理猿究院_夏燊1 小时前
SpringMVC 到底是怎么干活的?鶴哥只手遮天1 小时前
Spring Framework 7.0.9 深度剖析-05-配置元数据解析:XML、注解与 JavaConfigNGINX开源社区1 小时前
与我们交流:NGINX Gateway Fabric 与 NGINX Ingress Controller 社区会议鶴哥只手遮天2 小时前
Spring Framework 7.0.9 深度剖析-16-异步与调度十年Java程序媛2 小时前
Java 多线程基础与锁机制|进程线程、synchronized、volatile、Lock 面试全梳理