Search in sources :

Example 31 with Response

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

the class ElasticsearchTest method createDocument.

// 创建文档
// PUT方法 :在这个URL中存储文档
private static void createDocument(RestClient client) throws Exception {
    Request request = new Request("PUT", INDEX + "/" + TYPE + "/1");
    request.setEntity(new NStringEntity(// 
    "{" + // 
    "\"name\":\"hello\"," + // 
    "\"value\":\"world\"" + "}", 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 32 with Response

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

the class ElasticsearchTest method queryByField.

// 获取文档
private static void queryByField(RestClient client) throws Exception {
    Request request = new Request("GET", INDEX + "/" + TYPE + "/_search");
    request.setEntity(new NStringEntity(// 
    "{" + // 
    " \"query\": {" + // 
    " \"match\": {" + // 
    " \"name\": \"welcome\"" + // 
    " }" + // 
    " }" + "}", 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 33 with Response

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

the class ElasticsearchTest method queryAll.

// 获取文档
private static void queryAll(RestClient client) throws Exception {
    Request request = new Request("GET", INDEX + "/" + TYPE + "/_search");
    request.setEntity(new NStringEntity(// 
    "{" + // 
    " \"query\": {" + // 
    " \"match_all\": {}" + // 
    " }\n" + "}", 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 34 with Response

use of org.elasticsearch.client.Response 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 35 with Response

use of org.elasticsearch.client.Response 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)

Aggregations

Response (org.elasticsearch.client.Response)75 IOException (java.io.IOException)24 Request (org.elasticsearch.client.Request)19 BasicHeader (org.apache.http.message.BasicHeader)14 NStringEntity (org.apache.http.nio.entity.NStringEntity)14 HttpEntity (org.apache.http.HttpEntity)13 ResponseException (org.elasticsearch.client.ResponseException)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 HashMap (java.util.HashMap)9 RestClient (org.elasticsearch.client.RestClient)8 Map (java.util.Map)7 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)7 ArrayList (java.util.ArrayList)6 RestBulkItemResponse (org.janusgraph.diskstorage.es.rest.RestBulkResponse.RestBulkItemResponse)6 JSONArray (org.json.simple.JSONArray)6 JSONObject (org.json.simple.JSONObject)6 JSONParser (org.json.simple.parser.JSONParser)6 ParseException (org.json.simple.parser.ParseException)6 InputStream (java.io.InputStream)5 StringEntity (org.apache.http.entity.StringEntity)5