Search in sources :

Example 16 with Request

use of org.elasticsearch.client.Request in project yyl_example by Relucent.

the class ElasticsearchTest method deleteIndex.

// 删除索引
private static void deleteIndex(RestClient client) throws Exception {
    Request request = new Request("DELETE", INDEX);
    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 17 with Request

use of org.elasticsearch.client.Request in project yyl_example by Relucent.

the class ElasticsearchTest method existsIndices.

// 查询索引是否存在
private static boolean existsIndices(RestClient client) throws Exception {
    Request request = new Request("HEAD", INDEX);
    Response response = client.performRequest(request);
    boolean exists = response.getStatusLine().getReasonPhrase().equals("OK");
    System.out.println(exists);
    return exists;
}
Also used : Response(org.elasticsearch.client.Response) Request(org.elasticsearch.client.Request)

Example 18 with Request

use of org.elasticsearch.client.Request in project yyl_example by Relucent.

the class ElasticsearchTest method info.

// 验证ES集群是否搭建成功
private static void info(RestClient client) throws Exception {
    // curl -X GET "http://localhost:9200/_count?pretty"
    Request request = new Request("GET", "");
    request.addParameter("pretty", "true");
    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 19 with Request

use of org.elasticsearch.client.Request in project yyl_example by Relucent.

the class ElasticsearchTest method createIndex.

// 创建索引
private static void createIndex(RestClient client) throws Exception {
    Request request = new Request("PUT", INDEX);
    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 20 with Request

use of org.elasticsearch.client.Request in project yyl_example by Relucent.

the class ElasticsearchTest method createDocumentPost.

// 创建文档
// POST方法:在这个类型下存储文档
private static void createDocumentPost(RestClient client) throws Exception {
    Request request = new Request("POST", INDEX + "/" + TYPE);
    request.setEntity(new NStringEntity(// 
    "{" + // 
    "\"name\":\"welcome\"," + // 
    "\"value\":\"universe\"" + "}", ContentType.APPLICATION_JSON));
    Response response = client.performRequest(request);
    System.out.println(EntityUtils.toString(response.getEntity()));
}
Also used : Response(org.elasticsearch.client.Response) NStringEntity(org.apache.http.nio.entity.NStringEntity) Request(org.elasticsearch.client.Request)

Aggregations

Request (org.elasticsearch.client.Request)55 Response (org.elasticsearch.client.Response)35 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 IOException (java.io.IOException)12 HttpEntity (org.apache.http.HttpEntity)12 Request (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)12 NStringEntity (org.apache.http.nio.entity.NStringEntity)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 Map (java.util.Map)9 Collectors (java.util.stream.Collectors)9 StringEntity (org.apache.http.entity.StringEntity)7 RestClient (org.elasticsearch.client.RestClient)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 InputStream (java.io.InputStream)6 ContentType (org.apache.http.entity.ContentType)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 UncheckedIOException (java.io.UncheckedIOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4