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
相关推荐
0和1的舞者23 分钟前
《网络编程核心概念与 UDP Socket 组件深度解析》稚辉君.MCA_P8_Java24 分钟前
Gemini永久会员 Java动态规划oioihoii33 分钟前
C++语言演进之路:从“C with Classes”到现代编程基石N***738538 分钟前
SQL锁机制Java天梯之路42 分钟前
Java 初学者必看:接口 vs 抽象类,到底有什么区别?小熊officer1 小时前
Nginx中正向代理,反向代理,负载均衡信码由缰1 小时前
Java 应用容器化与部署方白羽1 小时前
Kotlin遇上Java 静态方法通往曙光的路上1 小时前
焚决糟糕篇q***65692 小时前
使用Canal将MySQL数据同步到ES(Linux)