We have begun integrating Hibernate Search into an existing Hibernate ORM application. We are now experimenting with Hibernate Search 5.8 beta3 with the intention of using it with an ElasticSearch cluster (application must be able to run in a multi-node configuration for redundancy/scalability).
The application provides the ability for users to define their own custom fields which we are currently storing as key-value pairs (map of strings) in a column within our relational model. We want to make these custom fields efficiently searchable.
Thus I implemented a FieldBridge and soon found that it was necessary to implement MetadataProvidingFieldBridge. I read that this is necessary for the sake of defining up front which fields are sortable. And in the case of elasticsearch I believe it is necessary because dynamic mapping is set to strict (as is the default case) when Hibernate Search creates the index.
For example:
Code:
public class MapKeyPerFieldBridge implements MetadataProvidingFieldBridge {
@Override
public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
@SuppressWarnings("unchecked")
Map<String, String> map = (Map<String, String>) value;
for (Map.Entry<String, String> entry : map.entrySet() ) {
Field field = new Field(name + '_' + entry.getKey(), entry.getValue(), luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector());
field.setBoost(luceneOptions.getBoost());
document.add(field);
}
}
@Override
public void configureFieldMetadata(String name, FieldMetadataBuilder builder) {
// The application does not know at this stage what custom fields are/will be defined at runtime
}
}
The dilemma however is that I don't know the schema up front as users have the ability to define their own custom fields at runtime. I thought of initiating a command to rebuild the index containing the custom records in this case but was wondering if there happens to be a better solution. I also read that the MetadataProvidingFieldBridge interface is still to be considered experimental (or at least subject to change).
Is there by chance a configurable option to have HibernateSearch create the index in ElasticSearch with the dynamic setting set to true (see
https://www.elastic.co/guide/en/elastic ... pping.html)?