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
相关推荐
r_oo_ki_e_1 小时前
牛牛与切割机Rain的Java大神之路2 小时前
Spring Boot 3 升级实战:真正吃掉工期的,是 MyBatis-Plus 坐标和 Security 6 重写泡海椒2 小时前
Java PDF 报表开发:一页简历的两种版式风格对比与折行避坑wuminyu2 小时前
OpenJDK学习笔记:Native事件队列与Java回调背压源码_空间2 小时前
基于Springboot在线考试系统(源码+文档)@SmartSi2 小时前
AgentScope Java 入门 14:如何使用 PlanNotebook 让智能体学会“先规划,后执行“AI开源软件3 小时前
用MQTT跑通一台模拟设备:看懂IoT产品、物模型和告警__万波__4 小时前
嵌入式存储技术--1.Flash物理存储智购科技无人售货机工厂店4 小时前
自动售货机振动与运输可靠性测试实战:跌落、振动与包装~YH程序员小杰@5 小时前
Java 统一报文转换 + 签名验签完整介绍