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++ 异常处理机制:异常捕获、自定义异常与实战应用yqzyy3 小时前
maven导入spring框架longzhen9z3 小时前
SpringSecurity踢出指定用户洛阳泰山3 小时前
开源智能体搭建平台MaxKB4j 技术文档我命由我123453 小时前
Android 开发 - UriMatcher(一个 URI 分类器)sinat_255487813 小时前
为 System.out 编写我们自己的包装类a8a3023 小时前
Springboot中CommandLineRunner的用法以及执行顺序的控制代码探秘者3 小时前
【大模型应用】1.了解RAGsevenlin3 小时前
Spring Boot 经典九设计模式全览