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
相关推荐
夜之眷属几秒前
Core dump 崩溃排查:JVM 宕机后,那份 core 文件怎么用 gdb 还原现场波加曼大王3 分钟前
# vLLM不要迷信PagedAttention神话,聊聊线上藏着的内部碎片陷阱SL_staff7 分钟前
目标健康度自检清单:开发者视角下的目标-计划-任务链路断点诊断for_ever_love__11 分钟前
MySQL 高频面试题 30 问:索引、事务、锁、日志、主从与分库分表(MySQL 8.0 版)神仙别闹13 分钟前
基于C++实现的贪吃蛇游戏平台布吉岛的石头22 分钟前
Java 程序员第 49 阶段11:Java 接 BERT:用 ONNX Runtime 做句向量推理niucloud-admin31 分钟前
JAVA V6 多商户商城 开发文档——JAVA服务端alexlifexyz1 小时前
写了个 Claude Code 插件:AI 写的 Java 违反阿里规约,就写不进文件威哥爱编程1 小时前
【AI全栈12-01】Spring Boot 为何是 AI 全栈后端优选威哥爱编程1 小时前
【AI全栈12-03】Spring Boot 用多模型路由把智能客服成本降下来