我试图利用弹性搜索与hibernate,使用hibernate-搜索弹性搜索集成。我有使用区分器策略的多租户数据,所以使用自动添加租户标识符的实体索引将是很好的。到目前为止,这似乎是可行的:
Session session = sessionFactory
.withOptions()
.tenantIdentifier("parkId-" + p.getId().toString())
.openSession();但是,在索引过程中,弹性搜索会因为strict_dynamic_mapping_exception而抱怨。
Response:
{
"index": {
"_index": "entities.productmodel",
"_type": "entities.ProductModel",
"_id": "parkId-1_29426",
"status": 400,
"error": {
"type": "strict_dynamic_mapping_exception",
"reason": "mapping set to strict, dynamic introduction of [__HSearch_TenantId] within [entities.ProductModel] is not allowed"
}
}
}尽管我正在重写hibernate搜索的默认行为,并将动态映射设置为true,但这一切都是事实,如文档所示。
configuration.setProperty("hibernate.search.default.elasticsearch.dynamic_mapping", "true");(其他设置是通过此方法正确设置的,因此我知道这不是问题。)
知道我错过了什么吗?即使将dynamic_mapping设置为false,也不会发生任何更改--弹性搜索仍然抱怨映射设置为严格。我的弹性搜索集群正在通过码头在本地运行。
发布于 2018-07-30 08:29:30
开发时,请确保在每次尝试之前重新生成架构。您不应该需要dynamic_mapping设置,但是如果您在尝试添加多租户之前生成了模式,并且没有更新模式,那么您将遇到类似于此的错误。
只需删除您的Elasticsearch集群中的索引,或者将属性hibernate.search.default.elasticsearch.index_schema_management_strategy设置为drop-and-create (不在生产中使用,您将丢失所有索引数据)。有关架构生成的更多信息,请参见文件的这一节。
发布于 2018-07-27 21:30:10
如果在ORM配置中设置了hibernate.multiTenancy,则承租者id字段应该是架构的一部分。
你有没有?
如果是这样的话,我们可能会在某个地方有一个bug,一个测试用例会有帮助。这里有一个测试用例模板:https://github.com/hibernate/hibernate-test-case-templates/tree/master/search/hibernate-search-elasticsearch/hibernate-search-elasticsearch-5。
https://stackoverflow.com/questions/51565308
复制相似问题