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
相关推荐
q***78786 分钟前
Spring学习——新建module模块q***116511 分钟前
在Nginx上配置并开启WebDAV服务的完整指南白起那么早23 分钟前
我又开发了一款idea插件-ContiNewGeneratorElasticsearch24 分钟前
Elasticsearch:如何在 ES|QL 中使用 FORK 及 FUSE 命令来实现混合搜索 - 9.1+装不满的克莱因瓶35 分钟前
【Java架构师体系课 | MySQL篇】③ Explain执行计划详解王煜苏37 分钟前
最新版idea2025 配置docker 打包spring-boot项目到生产服务器全流程,含期间遇到的坑李玮豪Jimmy1 小时前
Day18:二叉树part8(669.修剪二叉搜索树、108.将有序数组转换为二叉搜索树、538.把二叉搜索树转换为累加树)后端小张1 小时前
【AI 学习】AI Agent 开发进阶:架构、规划、记忆与工具编排西岭千秋雪_1 小时前
Kafka客户端整合leonardee1 小时前
Golang笔记——Interface类型