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 小时前
基于ssm的技能比赛报名管理系统29817vn0(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面代码雕刻家5 小时前
3.5.Maven-依赖管理-依赖配置&依赖传递!chen5 小时前
MyBatis-plus拓展之字段类型处理器、自动填充和乐观锁Jin、yz6 小时前
JAVA 八股va学弟6 小时前
Java 网络通信编程(6):视频通话pjw198809036 小时前
Spring Framework 中文官方文档jgyzl6 小时前
2026.3.11MyBatis-Plus基本使用与思考Full Stack Developme7 小时前
Java 常用通信协议及对应的框架( •̀∀•́ )9207 小时前
Spring Boot 启动报错 `BindException: Permission denied`杰克尼7 小时前
苍穹外卖--day10