use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class IndicesAdapterES7 method setReadOnly.
@Override
public void setReadOnly(String index) {
// https://www.elastic.co/guide/en/elasticsearch/reference/7.8/indices-update-settings.html
final Map<String, Object> settings = ImmutableMap.of("index", ImmutableMap.of("blocks", ImmutableMap.of(// Block writing.
"write", // Block writing.
true, // Allow reading.
"read", // Allow reading.
false, "metadata", // Allow getting metadata.
false)));
final UpdateSettingsRequest request = new UpdateSettingsRequest(index).settings(settings);
client.execute((c, requestOptions) -> c.indices().putSettings(request, requestOptions), "Couldn't set index " + index + " to read-only");
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class ElasticsearchClient method withTimeout.
public static RequestOptions withTimeout(RequestOptions requestOptions, Duration timeout) {
final RequestConfig.Builder requestConfigBuilder = (requestOptions == null || requestOptions.getRequestConfig() == null) ? RequestConfig.custom() : RequestConfig.copy(requestOptions.getRequestConfig());
final RequestConfig requestConfigWithTimeout = requestConfigBuilder.setSocketTimeout(Math.toIntExact(timeout.toMilliseconds())).build();
final RequestOptions.Builder requestOptionsBuilder = requestOptions == null ? RequestOptions.DEFAULT.toBuilder() : requestOptions.toBuilder();
return requestOptionsBuilder.setRequestConfig(requestConfigWithTimeout).build();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class MessagesAdapterES7 method get.
@Override
public ResultMessage get(String messageId, String index) throws DocumentNotFoundException {
final GetRequest getRequest = new GetRequest(index, messageId);
final GetResponse result = this.client.execute((c, requestOptions) -> c.get(getRequest, requestOptions));
if (!result.isExists()) {
throw new DocumentNotFoundException(index, messageId);
}
return ResultMessage.parseFromSource(messageId, index, result.getSource());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class MessagesAdapterES7 method analyze.
@Override
public List<String> analyze(String toAnalyze, String index, String analyzer) {
final AnalyzeRequest analyzeRequest = AnalyzeRequest.withIndexAnalyzer(index, analyzer, toAnalyze);
final AnalyzeResponse result = client.execute((c, requestOptions) -> c.indices().analyze(analyzeRequest, requestOptions));
return result.getTokens().stream().map(AnalyzeResponse.AnalyzeToken::getTerm).collect(Collectors.toList());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class PlainJsonApi method perform.
public JsonNode perform(Request request, String errorMessage) {
return client.execute((c, requestOptions) -> {
request.setOptions(requestOptions);
final Response response = c.getLowLevelClient().performRequest(request);
return objectMapper.readTree(response.getEntity().getContent());
}, errorMessage);
}
Aggregations