The idea would be to allow users to configure index options through annotations, similarly to @Table in Hibernate ORM. But since most options are backend-specific, we would need backend-specific annotations. Something like:
@Indexed
@ElasticsearchIndex(typeName = …)
public class MyType {
…
}
The Elasticsearch annotation (as well as the programmatic API equivalent) would live in a new module:
- They should not be directly in the Pojo module because it would prevent externally implemented backends to have their own annotations (due to the lack of extension point).
- They should not be directly in the Elasticsearch module because 1) it would require us to introduce annotations in the Backend SPI, which puts non-POJO mappers at a disadvantage (they would not benefit from this feature), and 2) it would require to add some indexConfiguration(Object) method in the programmatic API to pass an Elasticsearch-specific configuration object.
We will need a hibernate-search-orm-elasticsearch-starter Maven module to simplify dependency configuration, though. Suggestion of implementation Offer an SPI in the POJO mapper allowing to map annotations to "configurer" beans (much like what we do for bridges), and call a method on each configurer. Parameters passed to this methods would act as entry points to a programmatic API allowing to define index configuration. Something like this:
@Indexed
@ElasticsearchIndex(typeName = “foo”)
public class MyType {
…
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@ConfigurerMapping(builder = @ConfigurerReference(type = ElasticsearchConfigurerImpl.Builder.class))
public @interface ElasticsearchIndex {
String typeName();
}
public class ElasticsearchConfigurerImpl implements PojoIndexedTypeConfigurer {
public static class Builder implements AnnotationConfigurerBuilder<ElasticsearchIndex, ElasticsearchConfigurerImpl> {
@Override
public void initialize(ElasticsearchIndex annotation) {
...
}
@Override
public ElasticsearchConfigurerImpl build(BuildContext context) {
return new MyConfigurer( this );
}
}
private final String typeName;
private ElasticsearchConfigurerImpl(Builder builder) {
this.typeName = builder.typeName;
}
@Override
public void configure(Class<?> type, PojoIndexedTypeConfiguration typeConfiguration, IndexConfiguration indexConfiguration) {
indexConfiguration.withExtension( ElasticsearchExtension.get() ).typeName( typeName );
}
}
At some point in the future we might decide to promote this SPI to API, allowing users to define their own configurers. |