Configuring ElasticSearch host url with context path

I’m trying to use hibernate-search-elasticsearch to connect to an existing ElasticSearch server, but having problems with the configuration. Our ElasticSearch server has a context path with the version and environment (DEV, TEST, PROD) and I cannot find a way to specify that with the available config settings.

Server urls would be (for example: http://es1.mycompany.com/es/5x/DEV3)

If I try to configure that entire url as hibernate.search.default.elasticsearch.host it includes the context path in the host lookup and fails (java.net.UnknownHostException: es1.mycompany.com/es/5x/DEV3).

If I leave the context path off it tries to send a “get” request to just the host for ElasticSearch version info, and that, of course also fails because request needs to include the context path.

Is there another config setting that I’m missing? I can’t find any mention of one in the hibernate-search-elasticsearch documentation. Has anyone else run into this problem?

Unfortunately, you’re right, we don’t expose the pathPrefix configuration of the Elasticsearch REST client so you don’t have a way to do that.

I created https://hibernate.atlassian.net/browse/HSEARCH-3026 to track it.

Out of curiosity, which version of Hibernate Search are you trying?

I’m using hibernate search 5.9.0.Final, which appeared to be the latest stable version. Is there even an option to use a customized ElasticSearchClient (or factory) instead of the “DefaultElasticsearchClientFactory” or other classes so as to be able to set this? I couldn’t find one, which may kill hibernate-search as an option with this particular server.

The client contract is defined by ElasticsearchClientFactory which is a org.hibernate.search.engine.service.spi.Service so that means you can plug your own implementation.

Some basic steps are explained here: Implementing a Service but to force it to use an alternative service you might need to customize the bootstrap so that org.hibernate.search.cfg.spi.SearchConfiguration#getProvidedServices returns your custom type. This is typically meant for platform integrators, so unless you know how to do that it’s probably best you have a little patience and see if @gsmet nicely volunteers to implement a configuration option for this.

@Dedaimia_Kozlovsky

Cool, you’re using our latest version.

I drafted a fix here: https://github.com/gsmet/hibernate-search/tree/HSEARCH-3026-5.9 . It’s the only change in this branch.

Could you checkout my HSEARCH-3026-5.9 branch, build it with mvn clean install -DskipTests and test the 5.9.1-SNAPSHOT artifacts produced?

You will have to define this property in your configuration: hibernate.search.default.elasticsearch.path_prefix /es/5x/DEV3

Once you confirm us it works OK, we’ll merge and build a new release.

Thank you so much gsmet! I thought it would take months to get a fix back, if it happened at all. This was a very nice surprise.

I pulled your HSEARCH-3026-5.9 branch, build it, and tested my project with 5.9.1-SNAPSHOT. It connected to our ElasticSearch server fine now (with the /es/5x/DEV3 context path).

Unfortunately I can’t confirm that creating/updating an index works quite yet - looks like the ElasticSearch server admins didn’t set up my permissions correctly. I’m hoping that they’ll get it fixed within a day or so and then I can confirm full functionality.

OK, thanks. We are usually quite fast at fixing issues :slight_smile:

Let us know when you got everything setup, we’ll bake a release for you.

They fixed the permission issue, and I was able to create an index, update documents in it, and query for them, so I’d say the change is good!

I did realize that this still won’t work if people have multiple hosts with different context paths (e.g. http://server1/first/search/host, http://server2/second/search/host). Hopefully no one would do that, but is it worth mentioning in the documentation/comments for the change? Won’t matter one way or the other to me, we’ll only need one host url.

Yes I can add that in the documentation, it’s already in the comment of the added property.

By the way, do you mind if I wait until next Tuesday to make the release? I’d like to ask my colleague Yoann if he wants to include other fixes in this release. He’ll be back on Monday.

No hurry on my side for the release. Tuesday would be awesome. Adding these search features is part of a large project that won’t go into production for another month or so. We can use the 5.9.1-SNAPSHOT in the meantime for our development efforts.

@Dedaimia_Kozlovsky 5.9.1.Final release done. It might take a few hours to reach Maven Central but it’s on its way.

Thanks again for taking the time to request this feature. I suspect it will be useful to others.

I see 5.9.1.Final out in Maven Central. Thank you so much for making this change!