Search in sources :

Example 16 with RequestOptions

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

the class IndicesAdapterES7 method indexCreationDate.

@Override
public Optional<DateTime> indexCreationDate(String index) {
    final GetSettingsRequest request = new GetSettingsRequest().indices(index).indicesOptions(IndicesOptions.fromOptions(true, true, true, false));
    final GetSettingsResponse result = client.execute((c, requestOptions) -> c.indices().getSettings(request, requestOptions), "Couldn't read settings of index " + index);
    final Optional<String> creationDate = Optional.ofNullable(result.getIndexToSettings().get(index)).map(indexSettings -> indexSettings.get("index.creation_date"));
    return creationDate.map(Long::valueOf).map(instant -> new DateTime(instant, DateTimeZone.UTC));
}
Also used : GetSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) GetSettingsResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) DateTime(org.joda.time.DateTime)

Example 17 with RequestOptions

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

the class IndicesAdapterES7 method waitForRecovery.

@Override
public HealthStatus waitForRecovery(String index, int timeout) {
    final ClusterHealthRequest clusterHealthRequest = new ClusterHealthRequest(index).timeout(TimeValue.timeValueSeconds(timeout));
    clusterHealthRequest.waitForGreenStatus();
    final ClusterHealthResponse result = client.execute((c, requestOptions) -> c.cluster().health(clusterHealthRequest, requestOptions));
    return HealthStatus.fromString(result.getStatus().toString());
}
Also used : ClusterHealthResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)

Example 18 with RequestOptions

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

the class IndicesAdapterES7 method ensureIndexTemplate.

@Override
public boolean ensureIndexTemplate(String templateName, Map<String, Object> template) {
    final PutIndexTemplateRequest request = new PutIndexTemplateRequest(templateName).source(template);
    final AcknowledgedResponse result = client.execute((c, requestOptions) -> c.indices().putTemplate(request, requestOptions), "Unable to create index template " + templateName);
    return result.isAcknowledged();
}
Also used : AcknowledgedResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse) PutIndexTemplateRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutIndexTemplateRequest)

Example 19 with RequestOptions

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

the class IndicesAdapterES7 method aliases.

@Override
public Map<String, Set<String>> aliases(String indexPattern) {
    final GetAliasesRequest request = new GetAliasesRequest().indices(indexPattern).indicesOptions(IndicesOptions.fromOptions(false, false, true, false));
    final GetAliasesResponse result = client.execute((c, requestOptions) -> c.indices().getAlias(request, requestOptions), "Couldn't collect aliases for index pattern " + indexPattern);
    return result.getAliases().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().stream().map(AliasMetadata::alias).collect(Collectors.toSet())));
}
Also used : Terms(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.Terms) DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) MultiBucketsAggregation(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) LoggerFactory(org.slf4j.LoggerFactory) OpenIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.open.OpenIndexRequest) IndicesAdapter(org.graylog2.indexer.indices.IndicesAdapter) HealthStatus(org.graylog2.indexer.indices.HealthStatus) TimeValue(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue) Indices(org.graylog2.indexer.indices.Indices) Locale(java.util.Locale) Map(java.util.Map) GetAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) IndicesOptions(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions) JsonNode(com.fasterxml.jackson.databind.JsonNode) IndexRangeStats(org.graylog2.indexer.searches.IndexRangeStats) SearchType(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchType) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) StatsApi(org.graylog.storage.elasticsearch7.stats.StatsApi) Collection(java.util.Collection) DeleteIndexTemplateRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) Set(java.util.Set) Max(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.Max) IndexTemplatesExistRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.IndexTemplatesExistRequest) ClusterStateApi(org.graylog.storage.elasticsearch7.cluster.ClusterStateApi) Collectors(java.util.stream.Collectors) UpdateSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) List(java.util.List) AliasMetadata(org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.metadata.AliasMetadata) GetSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) GetAliasesResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.GetAliasesResponse) IndexMoveResult(org.graylog2.indexer.indices.IndexMoveResult) GetSettingsResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) Optional(java.util.Optional) BulkByScrollResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.index.reindex.BulkByScrollResponse) Min(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.Min) SearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse) ClusterHealthResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) FlushRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.flush.FlushRequest) HashMap(java.util.HashMap) CloseIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CloseIndexRequest) AggregationBuilders(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.AggregationBuilders) Inject(javax.inject.Inject) PutIndexTemplateRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutIndexTemplateRequest) PutMappingRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutMappingRequest) IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) Duration(com.github.joschi.jadconfig.util.Duration) Filter(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.filter.Filter) Nonnull(javax.annotation.Nonnull) SearchSourceBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) FilterAggregationBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) IndexSettings(org.graylog2.indexer.indices.IndexSettings) ElasticsearchClient.withTimeout(org.graylog.storage.elasticsearch7.ElasticsearchClient.withTimeout) CatApi(org.graylog.storage.elasticsearch7.cat.CatApi) IndexNotFoundException(org.graylog2.indexer.IndexNotFoundException) SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) DateTime(org.joda.time.DateTime) AcknowledgedResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse) ReindexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.index.reindex.ReindexRequest) ForceMergeRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest) ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) DeleteIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) CreateIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest) Consumer(java.util.function.Consumer) DeleteAliasRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.DeleteAliasRequest) Collectors.toList(java.util.stream.Collectors.toList) IndicesAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) QueryBuilders(org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilders) Message(org.graylog2.plugin.Message) Collections(java.util.Collections) GetAliasesResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.GetAliasesResponse) GetAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 20 with RequestOptions

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

the class IndexToolsAdapterES7 method count.

@Override
public long count(Set<String> indices, Optional<Set<String>> includedStreams) {
    final CountRequest request = new CountRequest(indices.toArray(new String[0]), buildStreamIdFilter(includedStreams)).indicesOptions(IndicesOptions.fromOptions(true, false, true, false));
    final CountResponse result = client.execute((c, requestOptions) -> c.count(request, requestOptions), "Unable to count documents of index.");
    return result.getCount();
}
Also used : CountRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.core.CountRequest) CountResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.core.CountResponse)

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