use of org.elasticsearch.client.Request in project hazelcast by hazelcast.
the class ElasticCatClient method nodes.
/**
* Returns list of nodes currently in ES cluster
*/
public List<Node> nodes() {
try {
Request r = new Request("GET", "/_cat/nodes");
r.addParameter("format", "json");
r.addParameter("full_id", "true");
r.addParameter("h", "id,ip,name,http_address,master");
Response res = withRetry(() -> client.performRequest(r), retries);
try (InputStreamReader reader = new InputStreamReader(res.getEntity().getContent(), UTF_8)) {
JsonArray array = Json.parse(reader).asArray();
List<Node> nodes = new ArrayList<>(array.size());
for (JsonValue value : array) {
Optional<Node> shard = convertToNode(value);
shard.ifPresent(nodes::add);
}
LOG.fine("Nodes: " + nodes);
return nodes;
}
} catch (IOException e) {
throw new JetException("Could not get ES cluster nodes", e);
}
}
use of org.elasticsearch.client.Request 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.Request 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.Request 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.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()));
}
Aggregations