Search in sources :

Example 56 with Request

use of org.elasticsearch.client.Request in project janusgraph by JanusGraph.

the class RestElasticSearchClient method countTotal.

@Override
public long countTotal(String indexName, Map<String, Object> requestData) throws IOException {
    final Request request = new Request(REQUEST_TYPE_GET, REQUEST_SEPARATOR + indexName + REQUEST_SEPARATOR + "_count");
    final byte[] requestDataBytes = mapper.writeValueAsBytes(requestData);
    if (log.isDebugEnabled()) {
        log.debug("Elasticsearch request: " + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(requestData));
    }
    final Response response = performRequest(request, requestDataBytes);
    try (final InputStream inputStream = response.getEntity().getContent()) {
        return mapper.readValue(inputStream, RestCountResponse.class).getCount();
    }
}
Also used : RestBulkItemResponse(org.janusgraph.diskstorage.es.rest.RestBulkResponse.RestBulkItemResponse) Response(org.elasticsearch.client.Response) ESScriptResponse(org.janusgraph.diskstorage.es.script.ESScriptResponse) InputStream(java.io.InputStream) Request(org.elasticsearch.client.Request)

Example 57 with Request

use of org.elasticsearch.client.Request in project janusgraph by JanusGraph.

the class RestElasticSearchClient method createStoredScript.

@Override
public void createStoredScript(String scriptName, Map<String, Object> script) throws IOException {
    Request request = new Request(REQUEST_TYPE_POST, REQUEST_SEPARATOR + "_scripts" + REQUEST_SEPARATOR + scriptName);
    performRequest(request, mapWriter.writeValueAsBytes(script));
}
Also used : Request(org.elasticsearch.client.Request)

Example 58 with Request

use of org.elasticsearch.client.Request in project janusgraph by JanusGraph.

the class RestElasticSearchClient method search.

private RestSearchResponse search(Map<String, Object> requestData, String path) throws IOException {
    final Request request = new Request(REQUEST_TYPE_POST, path);
    final byte[] requestDataBytes = mapper.writeValueAsBytes(requestData);
    if (log.isDebugEnabled()) {
        log.debug("Elasticsearch request: " + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(requestData));
    }
    final Response response = performRequest(request, requestDataBytes);
    try (final InputStream inputStream = response.getEntity().getContent()) {
        return mapper.readValue(inputStream, RestSearchResponse.class);
    }
}
Also used : RestBulkItemResponse(org.janusgraph.diskstorage.es.rest.RestBulkResponse.RestBulkItemResponse) Response(org.elasticsearch.client.Response) ESScriptResponse(org.janusgraph.diskstorage.es.script.ESScriptResponse) InputStream(java.io.InputStream) Request(org.elasticsearch.client.Request)

Example 59 with Request

use of org.elasticsearch.client.Request in project janusgraph by JanusGraph.

the class RestElasticSearchClient method clusterHealthRequest.

@Override
public void clusterHealthRequest(String timeout) throws IOException {
    Request clusterHealthRequest = new Request(REQUEST_TYPE_GET, REQUEST_SEPARATOR + "_cluster" + REQUEST_SEPARATOR + "health");
    clusterHealthRequest.addParameter("wait_for_status", "yellow");
    clusterHealthRequest.addParameter("timeout", timeout);
    final Response response = delegate.performRequest(clusterHealthRequest);
    try (final InputStream inputStream = response.getEntity().getContent()) {
        final Map<String, Object> values = mapReader.readValue(inputStream);
        if (!values.containsKey("timed_out")) {
            throw new IOException("Unexpected response for Elasticsearch cluster health request");
        } else if (!Objects.equals(values.get("timed_out"), false)) {
            throw new IOException("Elasticsearch timeout waiting for yellow status");
        }
    }
}
Also used : RestBulkItemResponse(org.janusgraph.diskstorage.es.rest.RestBulkResponse.RestBulkItemResponse) Response(org.elasticsearch.client.Response) ESScriptResponse(org.janusgraph.diskstorage.es.script.ESScriptResponse) InputStream(java.io.InputStream) Request(org.elasticsearch.client.Request) IOException(java.io.IOException)

Example 60 with Request

use of org.elasticsearch.client.Request in project janusgraph by JanusGraph.

the class RestElasticSearchClient method createMapping.

@Override
public void createMapping(String indexName, String typeName, Map<String, Object> mapping) throws IOException {
    Request request;
    if (useMappingTypes) {
        request = new Request(REQUEST_TYPE_PUT, REQUEST_SEPARATOR + indexName + REQUEST_SEPARATOR + "_mapping" + REQUEST_SEPARATOR + typeName);
        if (esVersion7) {
            request.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true");
        }
    } else {
        request = new Request(REQUEST_TYPE_PUT, REQUEST_SEPARATOR + indexName + REQUEST_SEPARATOR + "_mapping");
    }
    performRequest(request, mapWriter.writeValueAsBytes(mapping));
}
Also used : 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