Search in sources :

Example 56 with Request

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()));
}
Also used : Response(org.elasticsearch.client.Response) Request(org.elasticsearch.client.Request)

Example 57 with Request

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()));
}
Also used : Response(org.elasticsearch.client.Response) Request(org.elasticsearch.client.Request)

Example 58 with Request

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()));
}
Also used : Response(org.elasticsearch.client.Response) Request(org.elasticsearch.client.Request)

Example 59 with Request

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));
    }
}
Also used : Response(org.elasticsearch.client.Response) StatusLine(org.apache.http.StatusLine) InputStream(java.io.InputStream) Request(org.elasticsearch.client.Request)

Example 60 with Request

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Request(org.elasticsearch.client.Request) ArrayList(java.util.ArrayList) JsonValue(com.hazelcast.internal.json.JsonValue) IOException(java.io.IOException) JetException(com.hazelcast.jet.JetException) Response(org.elasticsearch.client.Response) JsonArray(com.hazelcast.internal.json.JsonArray) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

Request (org.elasticsearch.client.Request)54 Response (org.elasticsearch.client.Response)34 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 IOException (java.io.IOException)12 Request (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)12 HttpEntity (org.apache.http.HttpEntity)11 NStringEntity (org.apache.http.nio.entity.NStringEntity)11 Map (java.util.Map)10 Collectors (java.util.stream.Collectors)10 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)7 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 InputStream (java.io.InputStream)6 StringEntity (org.apache.http.entity.StringEntity)6 RestClient (org.elasticsearch.client.RestClient)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 HashMap (java.util.HashMap)5 Locale (java.util.Locale)5 ContentType (org.apache.http.entity.ContentType)5