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
相关推荐
NE_STOP13 小时前
MyBatis-配置文件解读及MyBatis为何不用编写Mapper接口的实现类后端AI实验室18 小时前
用AI写代码,我差点把漏洞发上线:血泪总结的10个教训程序员清风20 小时前
小红书二面:Spring Boot的单例模式是如何实现的?belhomme20 小时前
(面试题)Redis实现 IP 维度滑动窗口限流实践Be_Better20 小时前
学会与虚拟机对话---ASM开源之眼1 天前
《github star 加星 Taimili.com 艾米莉 》为什么Java里面,Service 层不直接返回 Result 对象?Maori3161 天前
放弃 SDKMAN!在 Garuda Linux + Fish 环境下的优雅 Java 管理指南用户908324602731 天前
Spring AI 1.1.2 + Neo4j:用知识图谱增强 RAG 检索(上篇:图谱构建)小王和八蛋1 天前
DecimalFormat 与 BigDecimal