Hibernate Search's dynamic templates are lost when using a custom mapping through schema_management.mapping_file

Description

See https://stackoverflow.com/questions/75806530/hibernate-search-6-trying-to-sort-dynamic-fields-with-field-templates-leads-to/75809346?noredirect=1#comment133790227_75809346

It seems the dynamic_templates section was dropped as soon as the developer set hibernate.search.schema_management.mapping_file .

While it seems reasonable to ignore most of Hibernate Search’s generated mapping when using a custom mapping (it’s too complex to do merging smartly), I think dynamic_templates should be retained if it’s not mentioned in the custom mapping, because it’s complex to get right manually, and because it’s similar to properties, which we decided to merge. I wouldn’t merge dynamic_templates, though: just use the one from the custom mapping if it exists, otherwise use Hibernate Search’s auto-generated one.

Similarly, we should probably preserve dynamicand routing in RootTypeMapping (without trying to merge them: just use the custom one or fall back to Hibernate Search’s generated one) . People wanting to override those can do so easily.

In short, I would:

  • Override org.hibernate.search.backend.elasticsearch.lowlevel.index.mapping.impl.AbstractTypeMapping#merge in RootTypeMapping

  • Implement RootTypeMapping#merge this way:

    • Call super() to merge properties as before (no change there)

    • For other mapping attributes, uses the custom value if defined, falling back to Hibernate Search’s.

  • Do not change anything for PropertyMapping#merge (no override, no handling of non-`properties` mapping attributes: no change there)

We’ll need to update the documentation to reflect those changes: https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#section-field-bridge

Activity

Show:
Fixed

Details

Assignee

Reporter

Sprint

Priority

Created March 27, 2023 at 8:48 AM
Updated June 2, 2023 at 1:33 PM
Resolved April 21, 2023 at 7:47 AM