Search in sources :

Example 46 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project graylog2-server by Graylog2.

the class ClusterStateApi method fields.

public Map<String, Set<String>> fields(Collection<String> indices) {
    final Request request = request(indices);
    final JsonNode jsonResponse = client.execute((c, requestOptions) -> {
        request.setOptions(requestOptions);
        final Response response = c.getLowLevelClient().performRequest(request);
        return objectMapper.readTree(response.getEntity().getContent());
    }, "Unable to retrieve fields from indices: " + String.join(",", indices));
    // noinspection UnstableApiUsage
    return Streams.stream(jsonResponse.path("metadata").path("indices").fields()).flatMap(index -> allFieldsFromIndex(index.getKey(), index.getValue())).collect(groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, Collectors.toSet())));
}
Also used : Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Set(java.util.Set) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) AbstractMap(java.util.AbstractMap) Stream(java.util.stream.Stream) Map(java.util.Map) Collectors.mapping(java.util.stream.Collectors.mapping) JsonNode(com.fasterxml.jackson.databind.JsonNode) Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request) JsonNode(com.fasterxml.jackson.databind.JsonNode) AbstractMap(java.util.AbstractMap) Map(java.util.Map)

Example 47 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project graylog2-server by Graylog2.

the class Scroll method scroll.

public ScrollResult scroll(ScrollCommand scrollCommand) {
    final SearchSourceBuilder searchQuery = searchRequestFactory.create(scrollCommand);
    searchQuery.fetchSource(scrollCommand.fields().toArray(new String[0]), new String[0]);
    scrollCommand.batchSize().ifPresent(batchSize -> searchQuery.size(Math.toIntExact(batchSize)));
    final SearchRequest request = scrollBuilder(searchQuery, scrollCommand.indices());
    final SearchResponse result = client.singleSearch(request, "Unable to perform scroll search");
    return scrollResultFactory.create(result, searchQuery.toString(), DEFAULT_SCROLLTIME, scrollCommand.fields(), scrollCommand.limit().orElse(-1));
}
Also used : SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) SearchSourceBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder) SearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse)

Example 48 with Request

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

the class EsClient method nodesStats.

// https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-stats.html
public NodeStatsResponse nodesStats() {
    return execute(() -> {
        Request request = new Request("GET", "/_nodes/stats/fs,process,jvm,indices,breaker");
        Response response = restHighLevelClient.getLowLevelClient().performRequest(request);
        return NodeStatsResponse.toNodeStatsResponse(gson.fromJson(EntityUtils.toString(response.getEntity()), JsonObject.class));
    });
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) ClearIndicesCacheResponse(org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse) ForceMergeResponse(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse) GetIndexResponse(org.elasticsearch.client.indices.GetIndexResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) Response(org.elasticsearch.client.Response) CreateIndexResponse(org.elasticsearch.client.indices.CreateIndexResponse) ClusterStatsResponse(org.sonar.server.es.response.ClusterStatsResponse) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse) ClearScrollResponse(org.elasticsearch.action.search.ClearScrollResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse) NodeStatsResponse(org.sonar.server.es.response.NodeStatsResponse) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) IndicesStatsResponse(org.sonar.server.es.response.IndicesStatsResponse) GetMappingsRequest(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) GetRequest(org.elasticsearch.action.get.GetRequest) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) ClearIndicesCacheRequest(org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) GetIndexRequest(org.elasticsearch.client.indices.GetIndexRequest) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) SearchRequest(org.elasticsearch.action.search.SearchRequest) UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) ForceMergeRequest(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest) RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) Request(org.elasticsearch.client.Request) PutMappingRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest) SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) JsonObject(com.google.gson.JsonObject)

Example 49 with Request

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

the class ElasticsearchIndexer method executeRaw.

@Override
public String executeRaw(String method, String url, String rawJson) throws IOException {
    Request request = new Request(method, url.startsWith("/") ? url : "/" + url);
    if (rawJson != null && !rawJson.isEmpty()) {
        request.setJsonEntity(rawJson);
    }
    Response response = client.getLowLevelClient().performRequest(request);
    if ("OPTIONS".equals(method)) {
        return response.getHeader("Allow");
    }
    HttpEntity entity = response.getEntity();
    return entity != null ? EntityUtils.toString(entity) : null;
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) Response(org.elasticsearch.client.Response) BulkByScrollResponse(org.elasticsearch.index.reindex.BulkByScrollResponse) DocWriteResponse(org.elasticsearch.action.DocWriteResponse) HttpEntity(org.apache.http.HttpEntity) IndexRequest(org.elasticsearch.action.index.IndexRequest) GetRequest(org.elasticsearch.action.get.GetRequest) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) SearchRequest(org.elasticsearch.action.search.SearchRequest) WriteRequest(org.elasticsearch.action.support.WriteRequest) UpdateByQueryRequest(org.elasticsearch.index.reindex.UpdateByQueryRequest) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) Request(org.elasticsearch.client.Request) SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest)

Example 50 with Request

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

the class ElasticsearchIndexer method deleteAll.

@Override
public boolean deleteAll(String indexName) throws IOException {
    Request post = new Request("POST", indexName + "/_delete_by_query?refresh");
    post.setEntity(new NStringEntity("{\"query\":{\"match_all\": {}}}", ContentType.APPLICATION_JSON));
    Response response = client.getLowLevelClient().performRequest(post);
    return response.getStatusLine().getStatusCode() == RestStatus.OK.getStatus();
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) Response(org.elasticsearch.client.Response) BulkByScrollResponse(org.elasticsearch.index.reindex.BulkByScrollResponse) DocWriteResponse(org.elasticsearch.action.DocWriteResponse) NStringEntity(org.apache.http.nio.entity.NStringEntity) IndexRequest(org.elasticsearch.action.index.IndexRequest) GetRequest(org.elasticsearch.action.get.GetRequest) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) SearchRequest(org.elasticsearch.action.search.SearchRequest) WriteRequest(org.elasticsearch.action.support.WriteRequest) UpdateByQueryRequest(org.elasticsearch.index.reindex.UpdateByQueryRequest) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) Request(org.elasticsearch.client.Request) SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest)

Aggregations

Request (org.elasticsearch.client.Request)54 Response (org.elasticsearch.client.Response)34 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 IOException (java.io.IOException)12 Request (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)12 HttpEntity (org.apache.http.HttpEntity)11 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 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 StringEntity (org.apache.http.entity.StringEntity)6 RestClient (org.elasticsearch.client.RestClient)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 HashMap (java.util.HashMap)5 Locale (java.util.Locale)5 ContentType (org.apache.http.entity.ContentType)5