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()));
}
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()));
}
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()));
}
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()));
}
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;
}
Aggregations