Search in sources :

Example 36 with Request

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());
}
Also used : Request(org.elasticsearch.client.Request)

Example 37 with Request

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));
}
Also used : Request(org.elasticsearch.client.Request)

Example 38 with Request

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));
        }
    }
}
Also used : Response(org.elasticsearch.client.Response) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStream(java.io.InputStream) Request(org.elasticsearch.client.Request) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 39 with Request

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()));
}
Also used : Response(org.elasticsearch.client.Response) Request(org.elasticsearch.client.Request)

Example 40 with Request

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()));
}
Also used : Response(org.elasticsearch.client.Response) Request(org.elasticsearch.client.Request)

Aggregations

Request (org.elasticsearch.client.Request)55 Response (org.elasticsearch.client.Response)35 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 IOException (java.io.IOException)12 HttpEntity (org.apache.http.HttpEntity)12 Request (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)12 NStringEntity (org.apache.http.nio.entity.NStringEntity)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 Map (java.util.Map)9 Collectors (java.util.stream.Collectors)9 StringEntity (org.apache.http.entity.StringEntity)7 RestClient (org.elasticsearch.client.RestClient)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 InputStream (java.io.InputStream)6 ContentType (org.apache.http.entity.ContentType)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 UncheckedIOException (java.io.UncheckedIOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4