use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions 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);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions 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())));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class IndicesAdapterES7 method markIndexReopened.
@Override
public void markIndexReopened(String index) {
final String aliasName = index + Indices.REOPENED_ALIAS_SUFFIX;
final IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
final IndicesAliasesRequest.AliasActions aliasAction = new IndicesAliasesRequest.AliasActions(IndicesAliasesRequest.AliasActions.Type.ADD).index(index).alias(aliasName);
indicesAliasesRequest.addAliasAction(aliasAction);
client.execute((c, requestOptions) -> c.indices().updateAliases(indicesAliasesRequest, requestOptions), "Couldn't create reopened alias for index " + index);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project hazelcast by hazelcast.
the class ElasticSourcePTest method when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForSearchRequest.
@Test
public void when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForSearchRequest() throws Exception {
when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(0, EQUAL_TO), Float.NaN));
// get different instance than default
TestSupport testSupport = runProcessor(request -> {
Builder builder = RequestOptions.DEFAULT.toBuilder();
builder.addHeader("TestHeader", "value");
return builder.build();
});
testSupport.expectOutput(emptyList());
ArgumentCaptor<RequestOptions> captor = forClass(RequestOptions.class);
verify(mockClient).search(any(), captor.capture());
RequestOptions capturedOptions = captor.getValue();
assertThat(capturedOptions.getHeaders()).extracting(h -> tuple(h.getName(), h.getValue())).containsExactly(tuple("TestHeader", "value"));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class ClusterAdapterES7 method clusterHealth.
private Optional<ClusterHealthResponse> clusterHealth(Collection<String> indices) {
final String[] indicesAry = indices.toArray(new String[0]);
if (!indices.isEmpty() && !indicesExist(indicesAry)) {
return Optional.empty();
}
final ClusterHealthRequest request = new ClusterHealthRequest(indicesAry).timeout(TimeValue.timeValueSeconds(Ints.saturatedCast(requestTimeout.toSeconds()))).indicesOptions(IndicesOptions.lenientExpand());
try {
return Optional.of(client.execute((c, requestOptions) -> c.cluster().health(request, requestOptions)));
} catch (ElasticsearchException e) {
if (LOG.isDebugEnabled()) {
LOG.error("{} ({})", e.getMessage(), Optional.ofNullable(e.getCause()).map(Throwable::getMessage).orElse("n/a"), e);
} else {
LOG.error("{} ({})", e.getMessage(), Optional.ofNullable(e.getCause()).map(Throwable::getMessage).orElse("n/a"));
}
return Optional.empty();
}
}
Aggregations