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
相关推荐
吃饱了得干活4 分钟前
缓存与数据库一致性:从理论到实战520拼好饭被践踏12 分钟前
JAVA+Agent学习day22笨蛋不要掉眼泪23 分钟前
Java虚拟机:堆的参数配置霸道流氓气质25 分钟前
SpringBoot中使用JasperReports 报表引擎 — 介绍、原理与使用实践花生了什么事o31 分钟前
DDD 分层架构:六层分层架构Y38153266233 分钟前
3 种 SERP 数据处理方案对比:流式 / 批处理 / 缓存Elastic 中国社区官方博客1 小时前
使用重新设计的 AutoOps 更快地进行 Elasticsearch 问题排查qq_150841991 小时前
SQL的insert和update二合一指令2601_964702891 小时前
Claude Opus 5 API 开发实战:对话、文本生成与结构化输出Sayuanni%31 小时前
Spring IOC