use of org.elasticsearch.client.Request in project graylog2-server by Graylog2.
the class NodeAdapterES7 method version.
@Override
public Optional<SearchVersion> version() {
final Request request = new Request("GET", "/");
final Optional<JsonNode> resp = Optional.of(jsonApi.perform(request, "Unable to retrieve cluster information"));
final Optional<String> version = resp.map(r -> r.path("version")).map(r -> r.path("number")).map(JsonNode::textValue);
final SearchVersion.Distribution distribution = resp.map(r -> r.path("version")).map(r -> r.path("distribution")).map(JsonNode::textValue).map(d -> d.toUpperCase(Locale.ROOT)).map(SearchVersion.Distribution::valueOf).orElse(SearchVersion.Distribution.ELASTICSEARCH);
return version.map(this::parseVersion).map(v -> SearchVersion.create(distribution, v));
}
use of org.elasticsearch.client.Request 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())));
}
use of org.elasticsearch.client.Request 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));
}
use of org.elasticsearch.client.Request in project graylog2-server by Graylog2.
the class CatApi method nodes.
public List<NodeResponse> nodes() {
final Request request = request("GET", "nodes");
request.addParameter("h", "id,name,role,host,ip,fileDescriptorMax,diskUsed,diskTotal,diskUsedPercent");
request.addParameter("full_id", "true");
return perform(request, new TypeReference<List<NodeResponse>>() {
}, "Unable to retrieve nodes list");
}
use of 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())));
}
Aggregations