Search in sources :

Example 41 with RequestOptions

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");
}
Also used : UpdateSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest)

Example 42 with RequestOptions

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();
}
Also used : RequestConfig(org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig) RequestOptions(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions)

Example 43 with RequestOptions

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());
}
Also used : DocumentNotFoundException(org.graylog2.indexer.messages.DocumentNotFoundException) GetRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetRequest) GetResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse)

Example 44 with RequestOptions

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());
}
Also used : AnalyzeRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.AnalyzeRequest) AnalyzeResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.AnalyzeResponse)

Example 45 with RequestOptions

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);
}
Also used : Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)

Aggregations

IndicesAliasesRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)8 CreateIndexRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest)8 Collectors (java.util.stream.Collectors)7 ClusterHealthRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)7 Request (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)7 Inject (javax.inject.Inject)6 DeleteIndexRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)6 UpdateSettingsRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest)6 DeleteIndexTemplateRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)6 IndexRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest)6 PutIndexTemplateRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutIndexTemplateRequest)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Collection (java.util.Collection)5 List (java.util.List)5 Map (java.util.Map)5 ClusterUpdateSettingsRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)5 BulkRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest)5 ElasticsearchClient (org.graylog.storage.elasticsearch7.ElasticsearchClient)5