| We could wrap the client with our own facade but that has two drawbacks:
- it implies it's an API / SPI which means we endorse its usage
- we would need to track the ElasticSearch API closely to make sure we expose any new things they might add
So I prefer proposal 1. : allow to grab a reference to "our" org.elasticsearch.client.RestClient, yet not introducing an ad-hoc method to accomplish this. There are two options to do that:
- either we explain how to use the ServiceRegistry to grab a ElasticsearchClientFactory - not ideal as you'd still need to initialize a new client instance, not to mention using the services is a bit verbose.
- enhance SearchFactory#unwrap - a bit tricky to implement but should be doable
My preference is the {{unwrap()} method. Drawbacks: I would not attempt to decorate/protect/enhance the returned client, which means people could in theory close it, change the hosts, or do other nasty things but IMO that's the level of control they are asking for. Ideally we could ask the Elasticsearch team to introduce a safe facade for such use cases but such a contract belongs in the Elasticsearch client project. |