Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose getClient #23

Open
mavencode01 opened this issue Dec 1, 2015 · 4 comments
Open

Expose getClient #23

mavencode01 opened this issue Dec 1, 2015 · 4 comments

Comments

@mavencode01
Copy link
Contributor

I've a requirement to expose the transport client in my application but seems the service does not correctly offer that.

I tried adding the getClient to the Elasticsearchservice but I got some exception relating to abstractmethod not defined.

Any ideas ?

@adrianluisgonzalez
Copy link
Member

You can't put it on the ElasticSearchService as this is a vert.x proxy service that can go over the event bus. It would be possible to put on the concrete implementation, but it is not a valid type for the proxy service.

@mavencode01
Copy link
Contributor Author

@adrianluisgonzalez that's exactly what am trying to achieve here...any suggestion on how to fix this ?

@adrianluisgonzalez
Copy link
Member

What do you need the transport client for? Should additional functionality be added to ElasticSearchService? If you really need it, then perhaps you shouldn't be using a vert.x service proxy.

If you are not using the proxy version of the service (ElasticSearchServiceVertxEBProxy) then you should have an instance of an InternalElasticSearchService which you can cast and call getClient().

@mavencode01
Copy link
Contributor Author

@adrianluisgonzalez Technically, I'm using another library - https://github.com/NLPchina/elasticsearch-sql/tree/elastic2.0 for parsing SQLs to Elasticsearch DSL and this requires the ES client.

Here is what I have to as a quick fix:

vertx.executeBlocking(action -> {

                Settings settings = Settings.builder()                
                                    .put("cluster.name", "myClusterName").build();

                esClient = TransportClient.builder().settings(settings).build();

                TransportClient client = TransportClient.builder().settings(settings).build();

                JsonArray transportHostArray = esConfig.getJsonArray("transportAddresses");

                transportHostArray.forEach(host -> {
                    JsonObject hostInfo = (JsonObject)host;
                    String hostAddress = hostInfo.getString("hostname");
                    int port = hostInfo.getInteger("port");

                    InetSocketTransportAddress transportAddress;
                    try {
                        transportAddress = new InetSocketTransportAddress(InetAddress.getByName(hostAddress), port);
                        client.addTransportAddress(transportAddress);                       
                    } catch (Exception e) {                     
                        action.fail(e);                 
                        e.printStackTrace();
                        return;
                    }
                });
                action.complete(client);
            }, res -> {
                if (res.succeeded()){                       
                    //client available!
                   esClient = (TransportClient)res.result()
                }
            });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants