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
相关推荐
摇滚侠几秒前
搭建前端开发环境 安装 nodejs 设置淘宝镜像 最简化最标准版本 不使用 NVM NVM 高版本无法安装低版本 nodejs花千树-0107 分钟前
兼容 ThreadLocal 的用户上下文透传方案:WebFlux 项目改造实践无人机9012 小时前
Delphi 网络编程实战:TIdTCPClient 与 TIdTCPServer 类深度解析lclcooky2 小时前
Spring 中使用Mybatis,超详细TeDi TIVE2 小时前
Spring Cloud Gateway:mnong3 小时前
Superpowers 项目设计分析扶苏-su3 小时前
Java--获取 Class 类对象东离与糖宝3 小时前
LangChain4j vs Spring AI:最新对比,Java企业级Agent开发96774 小时前
C++多线程2 如何优雅地锁门 (lock_guard) 多线程里的锁的种类老衲提灯找美女4 小时前
数据库事务