Filters based exclusively on mapper metadata for @IndexedEmbedded

Description

The includePaths filter in @IndexedEmbedded refers to index field paths. This has several drawbacks:

  • Part of the implementation has to be in the backend, which feels quite dirty.

  • This is not very consistent with the maxDepth filter, which applied to the @IndexedEmbedded only (depth of fields created within an included bridge is unlimited).

  • The filters cannot easily be applied to dynamic fields, so dynamic fields are always included as soon as their nearest static parent is included.

  • The filter can end up including some fields declared by a custom field bridge, but not others.

    • This does not make sense performance-wise as the fields will still be populated by the bridge, but ignored by the backend.

    • Worse, when we introduce support for bridge-defined predicates (), we may end up with dysfunctional predicates because only some fields are present, while the bridge expects all fields to be present.

  • We are forced to use inference to detect which bridges should be included or excluded, based on the fields they declared.

    • This code is unnecessarily complex.

    • This code does not work correctly with field templates, since we cannot know in advance whether dynamic fields will be included. In particular:

      • Bridges that declare field templates, but only ever add dynamic fields that would not match the includePaths, are included nonetheless.

      • Bridges that do not declare anything and rely on field templates declared by a parent (which is legal) are excluded.

We could get rid of most of the complexity by implementing filters differently, based on mapper metadata exclusively (mapping annotations and/or entity model).

Solution 1: property paths

We could rely on property paths instead of field paths. Only bridges applied to included properties are themselves included.

The major drawback is that there wouldn't be any way to filter out type bridges.

Solution 2: groups

We could rely on "groups", similarly to the @LazyGroup support in Hibernate ORM, or to the group support in Hibernate Validator.

One assigns groups to every @Field/@IndexedEmbedded, then references the groups in @IncludedEmbedded(includeGroups = ...).

The main problem with this solution is its complexity; Validator is using groups and I know they can be pretty complex to handle. We should definitely see what makes them so complex in Validator to avoid the same problems in Search.

For example:

Variation: overriding includeGroups

It would prevent us from supporting the use case mentioned in directly, but I believe the same effect could be achieved if we defined group filters as "overriding" instead of "composable": an @IndexedEmbedded(includeGroups = "a") that includes an @IndexedEmbedded(includeGroups = "b") would just act as if the contained @IndexedEmbedded included group "a", and only group "a".

For example:

There are pros and cons:

  • Pro: Groups may be easier to implement and understand: the various filters defined in indexed-embedded entities would no longer be relevant. One could argue that it's the opposite, though: the fact that filters defined in indexed-embedded entities are ignored can be confusing.

  • Con: it would become harder to manage cycles through group filtering: you would no longer be able to rely on indexed-embedded entities to filter out cycles through groups (since their group filters are ignored).

  • Con: the behavior would not be consistent with that of maxDepth.

Next

Deprecation

As a second step, we should probably deprecate includePaths and mark it for removal in a later major version (7+).

Going further: dynamic group selection

One could imagine to allow selecting groups dynamically. See HSEARCH-3971.

Going further: using field groups to select fields in the search DSL

We could address by contributing groups to the index metamodel: @GenericField(groups = "foo") would assign the group "foo" to the corresponding index field, which could then be targeted at query time by selecting the group "foo". See for more information.

Environment

None

Assignee

Unassigned

Reporter

Yoann Rodière

Labels

None

Suitable for new contributors

None

Pull Request

None

Feedback Requested

None

Components

Fix versions

Priority

Major
Configure