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
相关推荐
小江的记录本16 小时前
【Filter / Interceptor】过滤器(Filter)与拦截器(Interceptor)全方位对比解析(附底层原理 + 核心对比表)weisian15116 小时前
Java并发编程--16-ConcurrentHashMap演进:从分段锁到CAS+synchronized福运常在16 小时前
股票数据API(14)股票近年增发数据weixin_4462608516 小时前
一款提升工作效率的Claude HUD插件Java小王子呀16 小时前
JAVA 导出Excel中添加下拉框用POI短剑重铸之日1 天前
《ShardingSphere解读》07 读写分离:如何集成分库分表+数据库主从架构?知我Deja_Vu1 天前
【避坑指南】ConcurrentHashMap 并发计数优化实战daidaidaiyu1 天前
Spring IOC 源码学习 事务相关的 BeanDefinition 解析过程 (XML)鬼蛟1 天前
Spring————事务西门吹-禅1 天前
【sap fiori cds up error】