Override default @Field settings in Hibernate Search with Elasticsearch provider

Hi,
I’m integrating Hibernate Search in my project which previously used Spring Data Elasticsearch. It annoys me that it’s required to place @Field annotations everywhere: most of the fields in my entities need to be indexed, so it would be more convenient to index everything by default and have some @Ignore annotation to exclude unnecessary fields. Is it possible to configure that? Something like a class bridge or a custom analyzer?

Also, most of the indexed String fields need to be mapped as keywords. In order to do so, I have to use @Field(analyze = NO), but I wonder if there’s a way to configure that as a default too. I’ve tried to use a custom field bridge provider for String types, but it seems that Hibernate Search doesn’t allow to override builtin providers.
Thanks,
Sandeep,
Elasticsearch Developer

Hi Sandeep,

There’s no automatic way to index all the fields of an entity because, usually, you have to do some fine tuning of what is indexed, which analyzer should be used, should you mark an association with @IndexedEmbedded and so on.

I think the easiest way to do that would be to use Java reflection and the programmatic API: https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#hsearch-mapping-programmaticapi . You should be able to have something working pretty quickly.

As for the default analyzer, you can configure it (by default, it’s the StandardAnalyzer - not very happy with this choice personally but we have to keep it for compatibility) via the hibernate.search.analyzer property. See https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#analyzer .