Could not create connect to elastic server

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Could not create connect to elastic server

svcongnghe
This post has NOT been accepted by the mailing list yet.
This post was updated on .
Dear Mr/Mrs!

I want to use elastic search in my webapp, so this is my problem.
I create new client as below:
public static Client createClient() {
                try {
                        // Node node =
                        // nodeBuilder().clusterName(IConstants.CONFIG.CLUSTER_NAME).node();
                        // client = node.client();
                        Settings settings = ImmutableSettings.settingsBuilder()
                                        .put("client.transport.sniff", true)
                                        .put("cluster.name", IConstants.CONFIG.CLUSTER_NAME)
                                        .build();

                        TransportClient transportClient = new TransportClient(settings);
                        transportClient.addTransportAddress(
                                        new InetSocketTransportAddress(IConstants.CONFIG.NODE1,
                                                        IConstants.CONFIG.ES_PORT)).addTransportAddress(
                                        new InetSocketTransportAddress(IConstants.CONFIG.NODE2,
                                                        IConstants.CONFIG.ES_PORT));

                        if (transportClient.connectedNodes().size() == 0) {
                                System.out
                                                .println("There are no active nodes available for the transport, it will be automatically added once nodes are live!");
                        }

                        client = transportClient;
                } catch (Exception e) {
                        throw e;
                }
                return client;
        }

My problem is if i deploy web on server, then TransportClient transportClient = new TransportClient(settings); breaked without exception, so client = null;

But if i use some code to test it in local, it works.

Please, help me!
Thank you.