Search in sources :

Example 46 with RequestOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.

the class IndicesAdapterES7 method close.

@Override
public void close(String index) {
    final CloseIndexRequest request = new CloseIndexRequest(index);
    client.execute((c, requestOptions) -> c.indices().close(request, requestOptions), "Unable to close index " + index);
}
Also used : CloseIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CloseIndexRequest)

Example 47 with RequestOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.

the class V20200730000000_AddGl2MessageIdFieldAliasForEventsES7 method addGl2MessageIdFieldAlias.

@Override
public void addGl2MessageIdFieldAlias(Set<String> indexPrefixes) {
    final String[] prefixesWithWildcard = indexPrefixes.stream().map(p -> p + "*").toArray(String[]::new);
    final PutMappingRequest putMappingRequest = new PutMappingRequest(prefixesWithWildcard).indicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED).source(ImmutableMap.of("properties", ImmutableMap.of(FIELD_GL2_MESSAGE_ID, aliasMapping())));
    try {
        final AcknowledgedResponse acknowledgedResponse = client.execute((c, requestOptions) -> c.indices().putMapping(putMappingRequest, requestOptions));
        if (!acknowledgedResponse.isAcknowledged()) {
            throw new ElasticsearchException(errorMsgFor(prefixesWithWildcard) + " Elasticsearch failed to acknowledge.");
        }
    } catch (ElasticsearchException e) {
        throw new ElasticsearchException(errorMsgFor(prefixesWithWildcard), e);
    }
}
Also used : Inject(javax.inject.Inject) LinkedHashMap(java.util.LinkedHashMap) V20200730000000_AddGl2MessageIdFieldAliasForEvents(org.graylog.plugins.views.migrations.V20200730000000_AddGl2MessageIdFieldAliasForEvents) PutMappingRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutMappingRequest) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) Arrays(java.util.Arrays) ImmutableMap(com.google.common.collect.ImmutableMap) IndicesOptions(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions) AcknowledgedResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse) Set(java.util.Set) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) FIELD_GL2_MESSAGE_ID(org.graylog2.plugin.Message.FIELD_GL2_MESSAGE_ID) PutMappingRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutMappingRequest) AcknowledgedResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse) ElasticsearchException(org.graylog2.indexer.ElasticsearchException)

Example 48 with RequestOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.

the class MessagesES7IT method messageCount.

@Override
protected long messageCount(String indexName) {
    this.elasticsearch.elasticsearchClient().execute((c, requestOptions) -> c.indices().refresh(new RefreshRequest(), requestOptions));
    final CountRequest countRequest = new CountRequest(indexName);
    final CountResponse result = this.elasticsearch.elasticsearchClient().execute((c, requestOptions) -> c.count(countRequest, requestOptions));
    return result.getCount();
}
Also used : RefreshRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.refresh.RefreshRequest) CountRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.core.CountRequest) CountResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.core.CountResponse)

Example 49 with RequestOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.

the class ClientES7 method putSetting.

@Override
public void putSetting(String setting, String value) {
    final ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest();
    request.persistentSettings(Settings.builder().put(setting, value));
    client.execute((c, requestOptions) -> c.cluster().putSettings(request, requestOptions), "Unable to update ES cluster setting: " + setting + "=" + value);
}
Also used : ClusterUpdateSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)

Example 50 with RequestOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.

the class ClientES7 method waitForStatus.

private void waitForStatus(ClusterHealthStatus status, String... indices) {
    final ClusterHealthRequest clusterHealthRequest = new ClusterHealthRequest(indices);
    clusterHealthRequest.waitForStatus(status);
    client.execute((c, requestOptions) -> c.cluster().health(clusterHealthRequest, requestOptions));
}
Also used : ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)

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