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
相关推荐
晚安code33 分钟前
Java编程规范避坑指南:阿里开发手册15条强制规约实战解析Elasticsearch1 小时前
一个 ES|QL 查询替代两个:`WHERE IN` subquery 取代 Elasticsearch 中的复制粘贴循环小蒜学长1 小时前
“守望自然”招募志愿者环保行动网站的设计与实现(代码+数据库+LW)萧瑟余晖2 小时前
Java深入解析篇十八之响应式编程IKUN家族2 小时前
Spring MVC(五)weixin_BYSJ19872 小时前
【java项目分享】springboot阅读推荐平台10600小 黄 鸡2 小时前
JVM 核心总结一路向北North2 小时前
Spring AI(11) :ChatPDF-向量数据库、PDF处理、向量写入和向量搜索Data_Journal3 小时前
掌握网页抓取中的分页:完整指南莫逸风3 小时前
【AgentScope 2.0】05-文件系统(Filesystem)详解