use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project graylog2-server by Graylog2.
the class ElasticsearchBackendMultiSearchTest method everySearchTypeGeneratesOneESQuery.
@Test
public void everySearchTypeGeneratesOneESQuery() throws Exception {
final MultiSearchResponse response = TestMultisearchResponse.fromFixture("successfulMultiSearchResponse.json");
final List<MultiSearchResponse.Item> items = Arrays.stream(response.getResponses()).collect(Collectors.toList());
when(client.msearch(any(), any())).thenReturn(items);
final ESGeneratedQueryContext queryContext = this.elasticsearchBackend.generate(searchJob, query, new SearchConfig(Period.ZERO));
final List<SearchRequest> generatedRequest = run(searchJob, query, queryContext, Collections.emptySet());
assertThat(generatedRequest).hasSize(2);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project graylog2-server by Graylog2.
the class ElasticsearchBackendMultiSearchTest method multiSearchResultsAreAssignedToSearchTypes.
@Test
public void multiSearchResultsAreAssignedToSearchTypes() throws Exception {
final MultiSearchResponse response = TestMultisearchResponse.fromFixture("successfulMultiSearchResponse.json");
final List<MultiSearchResponse.Item> items = Arrays.stream(response.getResponses()).collect(Collectors.toList());
when(client.msearch(any(), any())).thenReturn(items);
final ESGeneratedQueryContext queryContext = this.elasticsearchBackend.generate(searchJob, query, new SearchConfig(Period.ZERO));
final QueryResult queryResult = this.elasticsearchBackend.doRun(searchJob, query, queryContext);
assertThat(queryResult.searchTypes()).containsOnlyKeys("pivot1", "pivot2");
final PivotResult pivot1Result = (PivotResult) queryResult.searchTypes().get("pivot1");
assertThat(pivot1Result.rows().get(0)).isEqualTo(PivotResult.Row.builder().key(ImmutableList.of()).source("leaf").addValue(PivotResult.Value.create(Collections.singletonList("avg(field1)"), 27220.273504273504, true, "row-leaf")).build());
final PivotResult pivot2Result = (PivotResult) queryResult.searchTypes().get("pivot2");
assertThat(pivot2Result.rows().get(0)).isEqualTo(PivotResult.Row.builder().key(ImmutableList.of()).source("leaf").addValue(PivotResult.Value.create(Collections.singletonList("max(field2)"), 42.0, true, "row-leaf")).build());
}
use of org.graylog.shaded.elasticsearch7.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())));
}
use of org.graylog.shaded.elasticsearch7.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));
}
use of org.graylog.shaded.elasticsearch7.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);
}
Aggregations