Java Code Examples for org.elasticsearch.client.RestHighLevelClient#ping()

The following examples show how to use org.elasticsearch.client.RestHighLevelClient#ping() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Elasticsearch6ApiCallBridge.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public RestHighLevelClient createClient(Map<String, String> clientConfig) throws IOException {
	RestClientBuilder builder = RestClient.builder(httpHosts.toArray(new HttpHost[httpHosts.size()]));
	restClientFactory.configureRestClientBuilder(builder);

	RestHighLevelClient rhlClient = new RestHighLevelClient(builder);

	if (LOG.isInfoEnabled()) {
		LOG.info("Pinging Elasticsearch cluster via hosts {} ...", httpHosts);
	}

	if (!rhlClient.ping()) {
		throw new RuntimeException("There are no reachable Elasticsearch nodes!");
	}

	if (LOG.isInfoEnabled()) {
		LOG.info("Created Elasticsearch RestHighLevelClient connected to {}", httpHosts.toString());
	}

	return rhlClient;
}
 
Example 2
Source File: Elasticsearch6ApiCallBridge.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public RestHighLevelClient createClient(Map<String, String> clientConfig) throws IOException {
	RestClientBuilder builder = RestClient.builder(httpHosts.toArray(new HttpHost[httpHosts.size()]));
	restClientFactory.configureRestClientBuilder(builder);

	RestHighLevelClient rhlClient = new RestHighLevelClient(builder);

	if (LOG.isInfoEnabled()) {
		LOG.info("Pinging Elasticsearch cluster via hosts {} ...", httpHosts);
	}

	if (!rhlClient.ping()) {
		throw new RuntimeException("There are no reachable Elasticsearch nodes!");
	}

	if (LOG.isInfoEnabled()) {
		LOG.info("Created Elasticsearch RestHighLevelClient connected to {}", httpHosts.toString());
	}

	return rhlClient;
}
 
Example 3
Source File: ElasticSearchPoolTest.java    From elasticsearch-pool with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
        Set<HostAndPort> nodes = new HashSet<HostAndPort>();
        nodes.add(new HostAndPort("172.31.4.14:9200","172.31.4.14",9200,"http"));
        ElasticSearchPoolConfig config = new ElasticSearchPoolConfig();
        config.setConnectTimeMillis(8000);
        config.setMaxTotal(100);
        config.setClusterName("elasticsearch");
        config.setNodes(nodes);
        ElasticSearchPool pool = new ElasticSearchPool(config);

        long start = System.currentTimeMillis();
        for(int i=0;i<1000;i++){
//            RestHighLevelClient client = pool.getResource();
            RestHighLevelClient client = new RestHighLevelClient(
                    RestClient.builder(
                            new HttpHost("172.31.4.14", 9200, "http")));
            boolean response = client.ping();
//            System.out.println("ping response: " + response);
//            pool.returnResource(client);
        }
        long end = System.currentTimeMillis();
        System.out.println("耗时(ms):"+(end-start));

    }
 
Example 4
Source File: ElasticSearchClientFactory.java    From elasticsearch-pool with Apache License 2.0 5 votes vote down vote up
public void destroyObject(PooledObject<RestHighLevelClient> pooledObject) throws Exception {
    RestHighLevelClient client = pooledObject.getObject();
    if(client!=null&&client.ping()){
        try {
            client.close();
        }catch (Exception e){
            //ignore
        }
    }
}
 
Example 5
Source File: ElasticSearchClientFactory.java    From elasticsearch-pool with Apache License 2.0 5 votes vote down vote up
public boolean validateObject(PooledObject<RestHighLevelClient> pooledObject) {
    RestHighLevelClient client = pooledObject.getObject();
    try {
        return client.ping();
    }catch(Exception e){
        return false;
    }
}
 
Example 6
Source File: ElasticSearchClient.java    From elasticsearch-pool with Apache License 2.0 5 votes vote down vote up
public boolean ping(){
    RestHighLevelClient client = null;
    try{
        client = getResource();
        boolean result = client.ping();
        returnResource(client);
        return result;
    }catch(Exception e){
        returnBrokenResource(client);
        return false;
    }
}
 
Example 7
Source File: PingApiMain.java    From elasticsearch-pool with Apache License 2.0 5 votes vote down vote up
public static void ping() throws IOException {
    try{
        RestHighLevelClient client = HighLevelClient.getInstance();

        boolean response = client.ping();

        System.out.println("ping response: " + response);

    }finally{
        HighLevelClient.close();
    }
}
 
Example 8
Source File: Elasticsearch7ApiCallBridge.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void verifyClientConnection(RestHighLevelClient client) throws IOException {
	if (LOG.isInfoEnabled()) {
		LOG.info("Pinging Elasticsearch cluster via hosts {} ...", httpHosts);
	}

	if (!client.ping(RequestOptions.DEFAULT)) {
		throw new RuntimeException("There are no reachable Elasticsearch nodes!");
	}

	if (LOG.isInfoEnabled()) {
		LOG.info("Elasticsearch RestHighLevelClient is connected to {}", httpHosts.toString());
	}
}
 
Example 9
Source File: Elasticsearch6ApiCallBridge.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void verifyClientConnection(RestHighLevelClient client) throws IOException {
	if (LOG.isInfoEnabled()) {
		LOG.info("Pinging Elasticsearch cluster via hosts {} ...", httpHosts);
	}

	if (!client.ping()) {
		throw new RuntimeException("There are no reachable Elasticsearch nodes!");
	}

	if (LOG.isInfoEnabled()) {
		LOG.info("Elasticsearch RestHighLevelClient is connected to {}", httpHosts.toString());
	}
}
 
Example 10
Source File: ElasticSearchClientFactory.java    From elasticsearch-pool with Apache License 2.0 4 votes vote down vote up
public void activateObject(PooledObject<RestHighLevelClient> pooledObject) throws Exception {
    RestHighLevelClient client = pooledObject.getObject();
    boolean response = client.ping();
}