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
相关推荐
程序员小凯6 分钟前
Spring MVC 分布式事务与数据一致性教程Jabes.yang24 分钟前
Java求职面试: 互联网医疗场景中的缓存技术与监控运维应用初级炼丹师(爱说实话版)39 分钟前
内存泄漏与内存溢出CryptoRzz1 小时前
越南k线历史数据、IPO新股股票数据接口文档学Java的bb1 小时前
MybatisPlus讓丄帝愛伱1 小时前
Mybatis Log Free插件使用problc1 小时前
Spring Cloud OpenFeign + Nacos 实战教程:像调用本地方法一样调用远程微服务重生之我要当java大帝1 小时前
java微服务-尚医通-编写医院设置接口上夫唯不争,故无尤也1 小时前
Tomcat 内嵌启动时找不到 Web 应用的路径心之伊始1 小时前
Netty线程模型与Tomcat线程模型对比分析