Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Hibernate Search, ElasticSearch and Dynamic Mapping
PostPosted: Fri Jun 16, 2017 8:45 pm 
Newbie

Joined: Fri Jun 16, 2017 5:26 pm
Posts: 7
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)?


Top
 Profile  
 
 Post subject: Re: Hibernate Search, ElasticSearch and Dynamic Mapping
PostPosted: Mon Jun 19, 2017 9:59 am 
Newbie

Joined: Fri Jun 16, 2017 5:26 pm
Posts: 7
Discovered that we can get away with not implementing MetadataProvidingFieldBridge for more recent version of ElasticSearch (5.4.1) but not for earlier version (2.4.4).

That said, would anyone be able to provide more insight on MetadataProvidingFieldBridge interface? Any plans to be able to control whether an index is created with Dynamic Mapping or not?


Top
 Profile  
 
 Post subject: Re: Hibernate Search, ElasticSearch and Dynamic Mapping
PostPosted: Fri Jun 23, 2017 10:01 am 
Newbie

Joined: Fri Jun 16, 2017 5:26 pm
Posts: 7
Noted that dynamic mapping is disabled in the case of elasticsearch 2.4.4 and 5.2.2 and enabled for 5.4.1... presume work that's being done on hibernate search 5.8 is with an ES version earlier than 5.4.1 - any recommendations on what version of ES we should focus on?


Top
 Profile  
 
 Post subject: Re: Hibernate Search, ElasticSearch and Dynamic Mapping
PostPosted: Tue Jul 04, 2017 4:03 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2535
Location: Third rock from the Sun
I would suggest focusing on the latest Elasticsearch, at this time 5.4.2. We mostly focus on the new/upcoming versions and will not evolve the older versions, other than basic patching.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Hibernate Search, ElasticSearch and Dynamic Mapping
PostPosted: Tue Jul 04, 2017 4:05 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2535
Location: Third rock from the Sun
Incidentally, we just merged today documentation improvements for this area. Sorry it was missing still.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.