Search in sources :

Example 11 with Request

use of org.graylog.shaded.elasticsearch7.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 12 with Request

use of org.graylog.shaded.elasticsearch7.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 13 with Request

use of org.graylog.shaded.elasticsearch7.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 14 with Request

use of org.graylog.shaded.elasticsearch7.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)

Example 15 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project immutables by immutables.

the class ElasticsearchOps method nextScroll.

/**
 * Fetches next results given a scrollId.
 */
Single<Json.Result> nextScroll(String scrollId) {
    // fetch next scroll
    final Request request = new Request("POST", "/_search/scroll");
    final ObjectNode payload = mapper.createObjectNode().put("scroll", "1m").put("scroll_id", scrollId);
    request.setJsonEntity(payload.toString());
    return transport.execute(request).map(r -> responseConverter().apply(r));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Request(org.elasticsearch.client.Request)

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