@Override
 protected Client createInstance() throws Exception {
   switch (configuration.getProtocol()) {
     case TRANSPORT:
       return createTransportClient();
     case NODE:
       return createNodeClient();
     default:
       LOGGER.error("Unsupported protocol [{}] for elastic client", configuration.getProtocol());
       throw new IllegalStateException(
           String.format(
               "Unsupported protocol [%s] for elastic client", configuration.getProtocol()));
   }
 }
  private Client createTransportClient() {
    Settings settings =
        ImmutableSettings.settingsBuilder()
            .put("cluster.name", configuration.getClusterName())
            .build();
    TransportClient transportClient = new TransportClient(settings);

    List<HostAddress> adresses = configuration.getHostsAddresses();

    for (HostAddress address : adresses) {
      transportClient.addTransportAddress(
          new InetSocketTransportAddress(address.getHostname(), address.getPort()));
    }

    return transportClient;
  }
  private Client createNodeClient() {
    Settings settings =
        ImmutableSettings.settingsBuilder()
            .put("cluster.name", configuration.getClusterName())
            .put("gateway.type", "none")
            // .put("index.number_of_shards",numberOfShards)
            // .put("index.number_of_replicas",0)
            .build();

    Node node = NodeBuilder.nodeBuilder().settings(settings).client(true).node();
    return node.client();
  }