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
相关推荐
拼搏@1 小时前
第十六天,7月10日,八股Sylvia-girl5 小时前
Java——抽象类Touper.8 小时前
Redis 基础详细介绍(Redis简单介绍,命令行客户端,Redis 命令,Java客户端)m0_535064608 小时前
C++模版编程:类模版与继承虾条_花吹雪9 小时前
Using Spring for Apache Pulsar:Message Productiontomorrow.hello9 小时前
Java并发测试工具Moso_Rx9 小时前
javaEE——synchronized关键字张小洛9 小时前
Spring AOP 是如何生效的(入口源码级解析)?寅鸷9 小时前
es里为什么node和shard不是一对一的关系DKPT9 小时前
Java设计模式之行为型模式(观察者模式)介绍与说明