private void openClient ( String clusterName ) { logger . info ( "Using ElasticSearch hostnames: {} " , Arrays . toString ( serverAddresses ) ) ; Settings settings = null ; Settings . Builder builder = Settings . builder ( ) ; if ( this . elasticUser != null && ! this . elasticUser . equals ( "" ) ) { builder . put ( "cluster.name" , clusterName ) . put ( "xpack.security.user" , this . elasticUser + ":" + this . elasticPassword ) ; // .put("shield.user", // this.elasticUser+":"+this.elasticPassword) } else { builder . put ( "cluster.name" , clusterName ) ; } if ( this . extendElasticsearchPropes != null && extendElasticsearchPropes . size ( ) > 0 ) { Iterator < Entry < Object , Object > > iterator = extendElasticsearchPropes . entrySet ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { Entry < Object , Object > entry = iterator . next ( ) ; builder . put ( ( String ) entry . getKey ( ) , String . valueOf ( entry . getValue ( ) ) ) ; } } settings = builder . build ( ) ; try { TransportClient transportClient = this . elasticUser != null && ! this . elasticUser . equals ( "" ) ? new PreBuiltXPackTransportClient ( settings ) : new PreBuiltTransportClient ( settings ) ; // TransportClient transportClient = new TransportClient(settings); for ( TransportAddress host : serverAddresses ) { transportClient . addTransportAddress ( host ) ; } if ( client != null ) { client . close ( ) ; } client = transportClient ; } catch ( RuntimeException e ) { e . printStackTrace ( ) ; } catch ( Throwable e ) { e . printStackTrace ( ) ; } }
Open client to elaticsearch cluster