logeyg
logeyg

Reputation: 559

Hibernate Search Dynamic Mapping

I am attempting to utilize elastic search with hibernate by using the hibernate-search elastic search integration. I have multi-tenant data that uses a discriminator strategy, so it would be great to index entities with that tenant identifier automatically added. This seems to work so far:

Session session = sessionFactory
                          .withOptions()
                            .tenantIdentifier("parkId-" + p.getId().toString())
                          .openSession();

However, during the index process, elastic search complains because of a 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"
    }
  }
}

This is all despite the fact that I am overriding the default behavior of hibernate search and setting dynamic mapping to true, as is shown in the docs:

configuration.setProperty("hibernate.search.default.elasticsearch.dynamic_mapping", "true");

(Other settings are properly being set via this method, so I know that is not the issue.)

Any idea what I'm missing? Even setting the dynamic_mapping to false results in no changes - elastic search still complains that the mapping is set to strict. My elastic search cluster is running locally via docker.

Upvotes: 2

Views: 1020

Answers (2)

yrodiere
yrodiere

Reputation: 9977

Make sure to re-generate your schema before each attempt when developping. You shouldn't need the dynamic_mapping setting for this, but if you generated the schema before you tried adding multitenancy, and did not update the schema since, you will experience errors like this one.

Just drop the indexes in your Elasticsearch cluster, or set the property hibernate.search.default.elasticsearch.index_schema_management_strategy to drop-and-create (NOT FOR USE IN PRODUCTION, YOU WILL LOSE ALL INDEX DATA). See this section of the documentation for more information about schema generation.

Upvotes: 1

Guillaume Smet
Guillaume Smet

Reputation: 10539

The tenant id field should be part of the schema if you have set hibernate.multiTenancy in your ORM configuration.

Did you?

If so, we might have a bug somewhere and a test case would help. We have a test case template here: https://github.com/hibernate/hibernate-test-case-templates/tree/master/search/hibernate-search-elasticsearch/hibernate-search-elasticsearch-5 .

Upvotes: 0

Related Questions