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
相关推荐
无巧不成书02186 小时前
30分钟入门Java:从历史到Hello World的小白指南疯狂成瘾者7 小时前
上传到 GitHub 的步骤总结zs宝来了8 小时前
Playwright 自动发布 CSDN 的完整实践吴声子夜歌9 小时前
TypeScript——基础类型(三)DynamicsAgg10 小时前
企业数字化底座-k8s企业实践系列第二篇pod创建调度森林里的程序猿猿10 小时前
并发设计模式222you11 小时前
四个主要的函数式接口Javatutouhouduan11 小时前
Java全栈面试进阶宝典:内容全面,题目高频!SEO-狼术11 小时前
RAD Studio 13.1 Florence adds