use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project yyl_example by Relucent.
the class ElasticsearchTest method catApi.
// 查看API信息
private static void catApi(RestClient client) throws Exception {
Request request = new Request("GET", "_cat");
Response response = client.performRequest(request);
System.out.println(EntityUtils.toString(response.getEntity()));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project yyl_example by Relucent.
the class ElasticsearchTest method deleteDocument.
// 删除文档
private static void deleteDocument(RestClient client) throws Exception {
Request request = new Request("DELETE", INDEX + "/" + TYPE + "/1");
Response response = client.performRequest(request);
System.out.println(EntityUtils.toString(response.getEntity()));
}
use of org.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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);
}
}
Aggregations