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
相关推荐
大模型丫丫2 小时前
工业级 RAG 为什么需要 Elasticsearch?霸道流氓气质2 小时前
Spring AI 技术细节:VectorStore 多库统一抽象今天AI了吗2 小时前
Codex 配置自定义 AI API 完整指南:从零到一接入你的专属模型学长毕业设计2 小时前
基于SpringBoot的健康食谱管理系统的设计与实现(源码+文档+讲解视频)珍珠先生2 小时前
P10 · 缺 MySQL 驱动 jar:ClassNotFoundException: com.mysql.cj.jdbc.Driverpnoker3 小时前
从工业软件到 AI 智能体:工业 AIoT 技术路线的系统梳理专注仿真3 小时前
Vapor框架构建及Swift for TensorFlow图像分析逃逸线LOF3 小时前
Spring的AOP简介砚底藏山河3 小时前
【量化纯GET实战 #21】用 pandas 做分析:把接口数据变成 DataFrameZzzzmo_3 小时前
Spring MVC