use of org.elasticsearch.client.Request in project yyl_example by Relucent.
the class ElasticsearchTest method getDocument.
// 获取文档
private static void getDocument(RestClient client) throws Exception {
Request request = new Request("GET", INDEX + "/" + TYPE + "/1");
Response response = client.performRequest(request);
System.out.println(EntityUtils.toString(response.getEntity()));
}
use of org.elasticsearch.client.Request in project spring-boot by spring-projects.
the class ElasticsearchRestHealthIndicator method doHealthCheck.
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
Response response = this.client.performRequest(new Request("GET", "/_cluster/health/"));
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
builder.down();
builder.withDetail("statusCode", statusLine.getStatusCode());
builder.withDetail("reasonPhrase", statusLine.getReasonPhrase());
return;
}
try (InputStream inputStream = response.getEntity().getContent()) {
doHealthCheck(builder, StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8));
}
}
use of org.elasticsearch.client.Request in project hazelcast by hazelcast.
the class ElasticCatClient method shards.
/**
* Returns list of shards for given indexes
*
* Only STARTED shards are returned.
*
* @param indices indexes to return shards for (wildcard format accepted)
*/
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
public List<Shard> shards(String... indices) {
Map<String, String> idToAddress = nodes().stream().collect(toMap(Node::getId, Node::getHttpAddress));
try {
Request r = new Request("GET", "/_cat/shards/" + String.join(",", indices));
r.addParameter("format", "json");
r.addParameter("h", "id,index,shard,prirep,docs,state,ip,node");
Response res = withRetry(() -> client.performRequest(r), retries);
try (InputStreamReader reader = new InputStreamReader(res.getEntity().getContent(), UTF_8)) {
JsonArray array = Json.parse(reader).asArray();
List<Shard> shards = new ArrayList<>(array.size());
for (JsonValue value : array) {
Optional<Shard> shard = convertToShard(value, idToAddress);
shard.ifPresent(shards::add);
}
LOG.log(FINE, "Shards " + shards);
return shards;
}
} catch (IOException e) {
throw new JetException("Could not get ES shards", e);
}
}
use of org.elasticsearch.client.Request in project hazelcast by hazelcast.
the class ElasticCatClient method master.
/**
* Returns current master of the ES cluster
*/
public Master master() {
try {
Request r = new Request("GET", "/_cat/master");
r.addParameter("format", "json");
Response res = withRetry(() -> client.performRequest(r), retries);
try (InputStreamReader reader = new InputStreamReader(res.getEntity().getContent(), UTF_8)) {
JsonArray array = Json.parse(reader).asArray();
JsonObject object = array.get(0).asObject();
return new Master(object.get("host").asString(), object.get("id").asString(), object.get("ip").asString(), object.get("node").asString());
}
} catch (IOException e) {
throw new JetException("Could not get ES cluster master", e);
}
}
use of org.elasticsearch.client.Request in project sonarqube by SonarSource.
the class EsClient method clusterStats.
// https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-stats.html
public ClusterStatsResponse clusterStats() {
return execute(() -> {
Request request = new Request("GET", "/_cluster/stats");
Response response = restHighLevelClient.getLowLevelClient().performRequest(request);
return ClusterStatsResponse.toClusterStatsResponse(gson.fromJson(EntityUtils.toString(response.getEntity()), JsonObject.class));
});
}
Aggregations