IndexLayoutStrategy per entity

I assume this would be a feature request but is there a way to allow for a IndexLayoutStrategy on a per-Entity basis?

I know I could create a custom IndexLayoutStrategy that could return different values based on the input, but I think it would be nice to be able to specify this on the Entity level or even specify the exact values to use.

For example using the @Indexed annotation one could. Following are scenarios I could see:

Supplying the information in the annotation

@Entity
@Indexed(index="widgets", 
         writeAlias="widget-write", 
         readAlias="widget-read")
class Widget { /* ... */ }

Omitting writeAlias means write directly to the index. Omitting the readAlias means read directly from the index.

@Entity
@Indexed(index="widgets")
class Widget { /* ... */ }

Omitting index uses a default value (e.g. “wigets” or “widgets-000001” in this case)

@Entity
@Indexed
class Widget { /* ... */ }

A custom class is specified to have hyper customized implementation. If layoutStrategy is supplied, supplying any of writeAlias, or readAlias would result in a startup failure.

@Entity
@Indexed(layoutStrategy=MyLayoutStrategy.class)
class Widget { /* ... */ }

Thoughts?

Configuring the index layout strategy on a per-index basis could be problematic.
There are two facets to the index layout strategy:

  1. Converting the Hibernate Hibernate Search name into the Elasticsearch index name/aliases, for schema management and to know which endpoints to hit when sending requests
  2. Converting the Elasticsearch index name returned for each hit by multi-index search queries into a Hibernate Search index name, to map the search hits back to the corresponding indexed types.

Item #2 would be challenging if there was one layout strategy per index. If all you have is an Elasticsearch index name, and multiple index layout strategies, how do you pick the layout strategy to use? That’s, in essence, the reason the IndexLayoutStrategy is per-backend, at least for now.

As to why there are no options like this in the @Indexed annotation, it’s basically because aliases are an Elasticsearch-specific feature, and @Indexed is a generic annotation, meant for both Elasticsearch and Lucene. We could introduce additional, Elasticsearch-specific annotations (HSEARCH-3306), but that’s planned for a later version.

As to why there are no options like this in the @Indexed annotation, it’s basically because aliases are an Elasticsearch-specific feature, and @Indexed is a generic annotation, meant for both Elasticsearch and Lucene. We could introduce additional, Elasticsearch-specific annotations (HSEARCH-3306), but that’s planned for a later version.

This makes complete senses. ES specific annotations would be great.

For now if/when I need this, I’ll just create a custom IndexLayoutStrategy.