use of org.elasticsearch.client.Request in project immutables by immutables.
the class ElasticsearchOps method deleteByQuery.
/**
* Delete documents using query API
* @see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html">Delete by query API</a>
*/
Single<WriteResult> deleteByQuery(ObjectNode query) {
Objects.requireNonNull(query, "query");
Request request = new Request("POST", String.format("/%s/_delete_by_query", index));
request.addParameter("refresh", "true");
request.setJsonEntity(query.toString());
return transport.execute(request).map(x -> WriteResult.unknown());
}
use of org.elasticsearch.client.Request in project immutables by immutables.
the class ElasticsearchOps method count.
/**
* Call {@code _count} endpoint to get count of documents matching a query.
* @see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-count.html">search-count</a>
*/
Single<Json.Count> count(ObjectNode query) {
final Request request = new Request("POST", String.format("/%s/_count", index));
request.setJsonEntity(query.toString());
return transport.execute(request).map(r -> convert(r, Json.Count.class));
}
use of org.elasticsearch.client.Request in project immutables by immutables.
the class ScrollingTest method assertNoActiveScrolls.
/**
* Ensures there are no pending scroll contexts in elastic search cluster.
* Queries {@code /_nodes/stats/indices/search} endpoint.
* @see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html">Indices Stats</a>
*/
// for errorprone
@SuppressWarnings("unused")
private void assertNoActiveScrolls() throws Exception {
// get node stats
final Response response = restClient.performRequest(new Request("GET", "/_nodes/stats/indices/search"));
try (InputStream is = response.getEntity().getContent()) {
final ObjectNode node = backend().objectMapper.readValue(is, ObjectNode.class);
final String path = "/indices/search/scroll_current";
final JsonNode scrollCurrent = node.with("nodes").elements().next().at(path);
if (scrollCurrent.isMissingNode()) {
throw new IllegalStateException("Couldn't find node at " + path);
}
final int activeScrolls = scrollCurrent.asInt();
if (activeScrolls != 0) {
throw new AssertionError(String.format("Expected no active scrolls but got %d. " + "Current index stats %s", activeScrolls, node));
}
}
}
use of org.elasticsearch.client.Request in project yyl_example by Relucent.
the class ElasticsearchTest method catApi.
// 查看API信息
private static void catApi(RestClient client) throws Exception {
Request request = new Request("GET", "_cat");
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 deleteDocument.
// 删除文档
private static void deleteDocument(RestClient client) throws Exception {
Request request = new Request("DELETE", INDEX + "/" + TYPE + "/1");
Response response = client.performRequest(request);
System.out.println(EntityUtils.toString(response.getEntity()));
}
Aggregations