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
相关推荐
凯子坚持 c2 分钟前
基于C++构建DeepSeek大模型推理SDK:从架构设计到工程落地星河耀银海3 分钟前
C++ 异常处理机制:异常捕获、自定义异常与实战应用yqzyy4 分钟前
maven导入spring框架longzhen9z12 分钟前
SpringSecurity踢出指定用户洛阳泰山19 分钟前
开源智能体搭建平台MaxKB4j 技术文档我命由我1234525 分钟前
Android 开发 - UriMatcher(一个 URI 分类器)sinat_2554878125 分钟前
为 System.out 编写我们自己的包装类a8a30225 分钟前
Springboot中CommandLineRunner的用法以及执行顺序的控制代码探秘者37 分钟前
【大模型应用】1.了解RAGsevenlin40 分钟前
Spring Boot 经典九设计模式全览