elasticsearch - Hibernate Search Mass Indexer 不会删除映射
问题描述
我目前正在使用 MassIndexer 来重新索引我的实体:
fullTextSession.createIndexer().startAndWait();
但是,我了解到 MassIndexer 不会删除现有的映射。似乎删除映射的唯一方法是将其设置index_schema_management_strategy
为“drop-and-create”,不建议在生产环境中使用。
在使用 MassIndexer 重新索引之前,我曾尝试使用 DELETE 索引 API 直接点击弹性搜索,但这会在我们的映射中引入奇怪的行为。
删除索引及其映射,然后使用 MassIndexer 重建该索引的推荐方法是什么?
解决方案
我找到了一种让休眠搜索完全删除映射和索引的方法,尽管这是一个相当好的解决方法。
通过实例化ElasticSearchService
这样的:
SearchIntegrator si = org.hibernate.search.orm.spi.SearchIntegratorHelper.extractFromEntityManagerFactory( fullTextSession.getEntityManagerFactory() );
ElasticsearchService elasticsearchService = si.getServiceManager().requestService(ElasticsearchService.class);
然后,您可以访问以下类:
ElasticsearchSchemaDropper schemaDropper = elasticsearchService.getSchemaDropper();
ElasticsearchSchemaCreator schemaCreator = elasticsearchService.getSchemaCreator();
并执行以下操作:
schemaDropper.drop(URLEncodedString.fromString("index you want to drop"), options);
schemaCreator.createIndex( indexMetadata, options );
schemaCreator.createMappings( indexMetadata, options );
这基本上就是drop-and-create
配置设置将为您做的事情。我们计划将其设置为一些外部服务,以便在我们想要完全重建索引时使用——包括映射和文档。
不幸的是,这感觉非常hacky,并且奇怪的是似乎没有更好的方法来做到这一点。
推荐阅读
- python - 如何将数据写入 TextIOWrapper?
- javascript - 如何在javascript中获取点击元素的索引位置
- google-tag-manager - Google Tag Manager - 解析动态数据层变量
- c# - 如何使用 ReactiveCommand?
- python - 将组分配给值
- vba - 在 VBA 中编写公式会导致编译错误 - 双引号
- python - 计算python列表中的字符串匹配百分比
- android - inputType =“数字|文本”不起作用 - Android
- javascript - Bootstrap maxlength 用 div 计数
- javascript - 创建一个复制数组元素的按钮