Hi,

I'm trying to use a singleton instance of client for multiple index 
creation. Below is the code for the same. But every time I'm getting 
instance as null and it's creating a new instance. Please let me know what 
I'm doing wrong

*singleton instance* :

public class ESClientSingleton {

public static Client instance ;

private ESClientSingleton()
{}
 public static Client getInstance()
{
if (instance == null)
  {
System.out.println("the instance is null...");
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder(); 
                settings.put("node.client", true); 
                settings.put("node.data", false); 
                settings.put("node.name", "node-client");
                settings.put("cluster.name", "elasticsearch");
                settings.build(); 
instance = new TransportClient(settings)
                .addTransportAddress(new 
InetSocketTransportAddress("10.203.251.142", 9300));
//instance = client;
return instance;
  }
return instance;
} 
}

*calling method* :

public static IndexResponse insertESDocument(String nodeName, String json)
  {  
  Client client = ESClientSingleton.getInstance();
  logger.debug("calling the es client");
  logger.debug("the json received as == "+json);
  IndexResponse response = 
client.prepareIndex("aricloud-nodes","node-entry",nodeName )
             .setSource(json)
             .execute()
             .actionGet();
  logger.debug("the document is successfully indexed...");
          System.out.println("the document is indexed...");
          //client.close();
         return response; 
  } 

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/36c95b86-5fa3-4af0-998a-a1b15b0bd1ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to