Search in sources :

Example 21 with Response

use of org.elasticsearch.client.Response in project storm by apache.

the class EsLookupBolt method lookupValuesInEs.

private Collection<Values> lookupValuesInEs(Tuple tuple) throws IOException {
    String index = tupleMapper.getIndex(tuple);
    String type = tupleMapper.getType(tuple);
    String id = tupleMapper.getId(tuple);
    Map<String, String> params = tupleMapper.getParams(tuple, new HashMap<>());
    Response response = client.performRequest("get", getEndpoint(index, type, id), params);
    return output.toValues(response);
}
Also used : Response(org.elasticsearch.client.Response)

Example 22 with Response

use of org.elasticsearch.client.Response in project storm by apache.

the class EsTestUtil method generateMockResponseException.

/**
 * Generate a mock {@link ResponseException}.
 * @return a mock {@link ResponseException}.
 * @throws IOException
 */
public static ResponseException generateMockResponseException() throws IOException {
    Response response = mock(Response.class);
    RequestLine requestLine = mock(RequestLine.class);
    StatusLine statusLine = mock(StatusLine.class);
    when(response.getRequestLine()).thenReturn(requestLine);
    when(response.getStatusLine()).thenReturn(statusLine);
    return new ResponseException(response);
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) Response(org.elasticsearch.client.Response) StatusLine(org.apache.http.StatusLine) RequestLine(org.apache.http.RequestLine) ResponseException(org.elasticsearch.client.ResponseException)

Example 23 with Response

use of org.elasticsearch.client.Response in project graylog2-server by Graylog2.

the class FieldMappingApi method fieldTypes.

public Map<String, FieldMapping> fieldTypes(String index) {
    final JsonNode result = client.execute((c, requestOptions) -> {
        final Response response = c.getLowLevelClient().performRequest(request(index));
        return objectMapper.readTree(response.getEntity().getContent());
    }, "Unable to retrieve field types of index " + index);
    final JsonNode fields = result.path(index).path("mappings").path("properties");
    // noinspection UnstableApiUsage
    return Streams.stream(fields.fields()).collect(Collectors.toMap(Map.Entry::getKey, entry -> FieldMapping.create(entry.getValue().path("type").asText(), entry.getValue().path("fielddata").asBoolean())));
}
Also used : Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response) Inject(javax.inject.Inject) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AutoValue(com.google.auto.value.AutoValue) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request) Optional(java.util.Optional) JsonNode(com.fasterxml.jackson.databind.JsonNode) Streams(com.google.common.collect.Streams) Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response) Collectors(java.util.stream.Collectors) Nullable(javax.annotation.Nullable) JsonNode(com.fasterxml.jackson.databind.JsonNode) Map(java.util.Map)

Example 24 with Response

use of org.elasticsearch.client.Response in project graylog2-server by Graylog2.

the class StatsApi method stats.

private JsonNode stats(Collection<String> indices, Collection<String> metrics, Consumer<Request> prepareRequest) {
    final StringBuilder endpoint = new StringBuilder();
    if (!indices.isEmpty()) {
        final String joinedIndices = String.join(",", indices);
        endpoint.append("/");
        endpoint.append(joinedIndices);
    }
    endpoint.append("/_stats");
    if (!metrics.isEmpty()) {
        final String joinedMetrics = String.join(",", metrics);
        endpoint.append("/");
        endpoint.append(joinedMetrics);
    }
    final Request request = new Request("GET", endpoint.toString());
    prepareRequest.accept(request);
    return client.execute((c, requestOptions) -> {
        request.setOptions(requestOptions);
        final Response response = c.getLowLevelClient().performRequest(request);
        return objectMapper.readTree(response.getEntity().getContent());
    }, "Unable to retrieve index stats for " + String.join(",", indices));
}
Also used : Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)

Example 25 with Response

use of org.elasticsearch.client.Response in project graylog2-server by Graylog2.

the class CatApi method perform.

private <R> R perform(Request request, TypeReference<R> responseClass, String errorMessage) {
    return client.execute((c, requestOptions) -> {
        request.setOptions(requestOptions);
        final Response response = c.getLowLevelClient().performRequest(request);
        return returnType(response, responseClass);
    }, errorMessage);
}
Also used : Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)

Aggregations

Response (org.elasticsearch.client.Response)75 IOException (java.io.IOException)24 Request (org.elasticsearch.client.Request)19 BasicHeader (org.apache.http.message.BasicHeader)14 NStringEntity (org.apache.http.nio.entity.NStringEntity)14 HttpEntity (org.apache.http.HttpEntity)13 ResponseException (org.elasticsearch.client.ResponseException)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 HashMap (java.util.HashMap)9 RestClient (org.elasticsearch.client.RestClient)8 Map (java.util.Map)7 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)7 ArrayList (java.util.ArrayList)6 RestBulkItemResponse (org.janusgraph.diskstorage.es.rest.RestBulkResponse.RestBulkItemResponse)6 JSONArray (org.json.simple.JSONArray)6 JSONObject (org.json.simple.JSONObject)6 JSONParser (org.json.simple.parser.JSONParser)6 ParseException (org.json.simple.parser.ParseException)6 InputStream (java.io.InputStream)5 StringEntity (org.apache.http.entity.StringEntity)5