Hibernate Search Mass Indexer 不会删除映射
Hibernate Search Mass Indexer Doesn't Drop Mappings
我目前正在像这样使用 MassIndexer 来重新索引我的实体:
fullTextSession.createIndexer().startAndWait();
但是,我了解到 MassIndexer 不会删除现有的映射。好像只有把index_schema_management_strategy
设置成'drop-and-create'才能去掉映射,不建议在生产环境中使用
我曾尝试使用 DELETE 索引直接点击弹性搜索 API 在 使用 MassIndexer 重新索引之前,但这会在我们的映射中引入奇怪的行为。
删除索引及其映射,然后使用 MassIndexer 重建该索引的推荐方法是什么?
MassIndexer 的目的是帮助更新索引内容作为灾难恢复策略或构建初始索引状态,因为索引通常保持同步。
这并不意味着对索引执行更高级的生命周期操作,例如实时架构更改。
为此,我建议您至少 stop/restart Hibernate 应用程序(这样您就可以使用其他 属性)并且很可能通过外部脚本或作为你的发布过程。
让 Hibernate Search 管理索引模式是为了在开发过程中提供便利。
我找到了一种让休眠搜索完全删除映射和索引的方法,尽管这是一个很好的解决方法。
通过像这样实例化一个 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,奇怪的是似乎没有更好的方法来做到这一点。
我目前正在像这样使用 MassIndexer 来重新索引我的实体:
fullTextSession.createIndexer().startAndWait();
但是,我了解到 MassIndexer 不会删除现有的映射。好像只有把index_schema_management_strategy
设置成'drop-and-create'才能去掉映射,不建议在生产环境中使用
我曾尝试使用 DELETE 索引直接点击弹性搜索 API 在 使用 MassIndexer 重新索引之前,但这会在我们的映射中引入奇怪的行为。
删除索引及其映射,然后使用 MassIndexer 重建该索引的推荐方法是什么?
MassIndexer 的目的是帮助更新索引内容作为灾难恢复策略或构建初始索引状态,因为索引通常保持同步。
这并不意味着对索引执行更高级的生命周期操作,例如实时架构更改。
为此,我建议您至少 stop/restart Hibernate 应用程序(这样您就可以使用其他 属性)并且很可能通过外部脚本或作为你的发布过程。
让 Hibernate Search 管理索引模式是为了在开发过程中提供便利。
我找到了一种让休眠搜索完全删除映射和索引的方法,尽管这是一个很好的解决方法。
通过像这样实例化一个 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,奇怪的是似乎没有更好的方法来做到这一点。