Search in sources :

Example 16 with Request

use of org.graylog.shaded.elasticsearch7.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 17 with Request

use of org.graylog.shaded.elasticsearch7.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 18 with Request

use of org.graylog.shaded.elasticsearch7.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 19 with Request

use of org.graylog.shaded.elasticsearch7.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)

Example 20 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project immutables by immutables.

the class IndexOps method mapping.

/**
 * Return mapping for current index
 */
Single<Mapping> mapping() {
    final String uri = String.format(Locale.ROOT, "/%s/_mapping", index);
    final Request request = new Request("GET", uri);
    return transport.execute(request).map(response -> mapper.readValue(response.getEntity().getContent(), ObjectNode.class)).map(root -> {
        ObjectNode properties = (ObjectNode) root.elements().next().get("mappings");
        if (properties == null) {
            throw new IllegalStateException(String.format("No mappings found for index %s (after request %s)", index, request));
        }
        ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
        Json.visitMappingProperties(properties, builder::put);
        return Mapping.ofElastic(builder.build());
    });
}
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) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Request (org.elasticsearch.client.Request)55 Response (org.elasticsearch.client.Response)35 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 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 Map (java.util.Map)10 Collectors (java.util.stream.Collectors)10 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 StringEntity (org.apache.http.entity.StringEntity)7 RestClient (org.elasticsearch.client.RestClient)7 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)7 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 InputStream (java.io.InputStream)6 HashMap (java.util.HashMap)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 Locale (java.util.Locale)5 ContentType (org.apache.http.entity.ContentType)5