Search in sources :

Example 21 with Request

use of org.elasticsearch.client.Request in project immutables by immutables.

the class ElasticsearchOps method nextScroll.

/**
 * Fetches next results given a scrollId.
 */
Single<Json.Result> nextScroll(String scrollId) {
    // fetch next scroll
    final Request request = new Request("POST", "/_search/scroll");
    final ObjectNode payload = mapper.createObjectNode().put("scroll", "1m").put("scroll_id", scrollId);
    request.setJsonEntity(payload.toString());
    return transport.execute(request).map(r -> responseConverter().apply(r));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Request(org.elasticsearch.client.Request)

Example 22 with Request

use of org.elasticsearch.client.Request in project immutables by immutables.

the class ElasticsearchOps method closeScroll.

Completable closeScroll(Iterable<String> scrollIds) {
    final ObjectNode payload = mapper.createObjectNode();
    final ArrayNode array = payload.withArray("scroll_id");
    scrollIds.forEach(array::add);
    final Request request = new Request("DELETE", "/_search/scroll");
    request.setJsonEntity(payload.toString());
    return transport.execute(request).ignoreElement();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Request(org.elasticsearch.client.Request) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 23 with Request

use of org.elasticsearch.client.Request in project immutables by immutables.

the class ElasticsearchOps method insertDocument.

Single<WriteResult> insertDocument(ObjectNode document) throws IOException {
    Objects.requireNonNull(document, "document");
    String uri = String.format(Locale.ROOT, "/%s/_doc?refresh", index);
    StringEntity entity = new StringEntity(mapper().writeValueAsString(document), ContentType.APPLICATION_JSON);
    final Request r = new Request("POST", uri);
    r.setEntity(entity);
    return transport.execute(r).map(x -> WriteResult.unknown());
}
Also used : StringEntity(org.apache.http.entity.StringEntity) Request(org.elasticsearch.client.Request)

Example 24 with Request

use of org.elasticsearch.client.Request in project immutables by immutables.

the class ElasticsearchOps method searchRaw.

Single<Json.Result> searchRaw(ObjectNode query, Map<String, String> httpParams) {
    final Request request = new Request("POST", String.format("/%s/_search", index));
    httpParams.forEach(request::addParameter);
    request.setJsonEntity(query.toString());
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "Performing search {0} on {1}", new Object[] { query, request });
    }
    return transport.execute(request).map(r -> responseConverter().apply(r));
}
Also used : Request(org.elasticsearch.client.Request)

Example 25 with Request

use of org.elasticsearch.client.Request in project immutables by immutables.

the class IndexOps method version.

Single<Version> version() {
    final Request request = new Request("GET", "/");
    // version extract function
    final Function<ObjectNode, Version> fn = node -> Version.of(node.get("version").get("number").asText());
    return transport.execute(request).map(response -> mapper.readValue(response.getEntity().getContent(), ObjectNode.class)).map(fn::apply);
}
Also used : RestClient(org.elasticsearch.client.RestClient) ImmutableMap(com.google.common.collect.ImmutableMap) Completable(io.reactivex.Completable) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpEntity(org.apache.http.HttpEntity) ContentType(org.apache.http.entity.ContentType) StringEntity(org.apache.http.entity.StringEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Single(io.reactivex.Single) Request(org.elasticsearch.client.Request) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) Locale(java.util.Locale) Map(java.util.Map) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) 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