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
相关推荐
JAVA学习通7 分钟前
《大营销平台系统设计实现》 - 营销服务 第5节:抽奖前置规则过滤斯特凡今天也很帅10 分钟前
新建数据源报错No bean named ‘SqlSessionFactorykf‘ available带刺的坐椅10 分钟前
用 Solon AI 从零构建 MCP 工具服务:让 AI Agent 拥有真实世界的能力TheRouter16 分钟前
PromptCaching 工程实践:把LLM 调用成本砍掉80%寻道码路16 分钟前
LangChain4j Java AI 应用开发实战(二):大模型参数调优实战:Temperature、TopP、MaxTokens 深度解析XiYang-DING23 分钟前
【Spring】 AjaxSimonKing31 分钟前
IP定位库的完美替代品:ip2region,开源、免费!XiYang-DING31 分钟前
【Spring】Lombok凤山老林32 分钟前
AI辅助编程:Copilot在Java开发中的最佳实践ew4521833 分钟前
【Java】Apache POI 终极封装:支持多表格循环、图片插入、日期格式化的Word导出工具类(兼容POI3.17+)