Search in sources :

Example 1 with GetAliasesResponse

use of org.elasticsearch.client.GetAliasesResponse in project graylog2-server by Graylog2.

the class IndicesAdapterES7 method resolveAlias.

@Override
public Set<String> resolveAlias(String alias) {
    final GetAliasesRequest request = new GetAliasesRequest().aliases(alias);
    final GetAliasesResponse result = client.execute((c, requestOptions) -> c.indices().getAlias(request, requestOptions));
    return result.getAliases().keySet();
}
Also used : GetAliasesResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.GetAliasesResponse) GetAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)

Example 2 with GetAliasesResponse

use of org.elasticsearch.client.GetAliasesResponse 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 3 with GetAliasesResponse

use of org.elasticsearch.client.GetAliasesResponse in project jackrabbit-oak by apache.

the class TestHelper method cleanupRemoteElastic.

/*
    Deletes the remote elastic index from the elastic server.
     */
public static void cleanupRemoteElastic(ElasticConnection connection, String indexName) throws IOException {
    String alias = ElasticIndexNameHelper.getElasticSafeIndexName(connection.getIndexPrefix(), "/oak:index/" + indexName);
    // get and delete the indexes which this alias is pointing to
    GetAliasesRequest getAliasesRequest = new GetAliasesRequest(alias);
    GetAliasesResponse aliasesResponse = connection.getClient().indices().getAlias(getAliasesRequest, RequestOptions.DEFAULT);
    Map<String, Set<AliasMetadata>> aliases = aliasesResponse.getAliases();
    for (String remoteIndexName : aliases.keySet()) {
        AcknowledgedResponse deleteIndexResponse = connection.getClient().indices().delete(new DeleteIndexRequest(remoteIndexName), RequestOptions.DEFAULT);
        if (!deleteIndexResponse.isAcknowledged()) {
            LOG.warn("Delete index call not acknowledged for index " + remoteIndexName + " .Please check if remote index deleted or not.");
        }
    }
}
Also used : Set(java.util.Set) GetAliasesResponse(org.elasticsearch.client.GetAliasesResponse) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)

Example 4 with GetAliasesResponse

use of org.elasticsearch.client.GetAliasesResponse in project herd by FINRAOS.

the class IndexFunctionsDaoTest method testUpdateIndexDocumentsFunctionWithFailures.

@Test
public void testUpdateIndexDocumentsFunctionWithFailures() throws Exception {
    // Build mocks
    GetAliasesResponse getAliasesResponse = mock(GetAliasesResponse.class);
    IndicesClient indicesClient = mock(IndicesClient.class);
    RestHighLevelClient restHighLevelClient = mock(RestHighLevelClient.class);
    AliasMetadata AliasMetadata = mock(AliasMetadata.class);
    BulkResponse bulkResponse = mock(BulkResponse.class);
    // Create objects needed for the test.
    Map<String, String> documentMap = new HashMap<>();
    documentMap.put(SEARCH_INDEX_DOCUMENT, SEARCH_INDEX_DOCUMENT_JSON);
    Set<AliasMetadata> AliasMetadataSet = new HashSet<>();
    AliasMetadataSet.add(AliasMetadata);
    Map<String, Set<AliasMetadata>> aliases = new HashMap<>();
    aliases.put(SEARCH_INDEX_ALIAS_BDEF, AliasMetadataSet);
    // Mock the calls to external methods
    when(elasticsearchRestHighLevelClientFactory.getRestHighLevelClient()).thenReturn(restHighLevelClient);
    when(restHighLevelClient.indices()).thenReturn(indicesClient);
    when(indicesClient.getAlias(any(GetAliasesRequest.class), eq(RequestOptions.DEFAULT))).thenReturn(getAliasesResponse);
    when(getAliasesResponse.getAliases()).thenReturn(aliases);
    when(restHighLevelClient.bulk(any(BulkRequest.class), eq(RequestOptions.DEFAULT))).thenReturn(bulkResponse);
    when(bulkResponse.hasFailures()).thenReturn(true);
    when(bulkResponse.buildFailureMessage()).thenReturn(ERROR_MESSAGE);
    // Call the method under test
    indexFunctionsDao.updateIndexDocuments(SEARCH_INDEX_NAME, documentMap);
    // Verify the calls to external methods
    verify(elasticsearchRestHighLevelClientFactory, times(2)).getRestHighLevelClient();
    verify(restHighLevelClient).indices();
    verify(restHighLevelClient).bulk(any(BulkRequest.class), eq(RequestOptions.DEFAULT));
    verify(indicesClient).getAlias(any(GetAliasesRequest.class), eq(RequestOptions.DEFAULT));
    verify(getAliasesResponse).getAliases();
    verify(bulkResponse).hasFailures();
    verify(bulkResponse).buildFailureMessage();
    verify(restHighLevelClient, times(2)).close();
    verifyNoMoreInteractions(bulkResponse, elasticsearchRestHighLevelClientFactory, getAliasesResponse, indicesClient, restHighLevelClient);
}
Also used : AliasMetadata(org.elasticsearch.cluster.metadata.AliasMetadata) Set(java.util.Set) HashSet(java.util.HashSet) GetAliasesResponse(org.elasticsearch.client.GetAliasesResponse) HashMap(java.util.HashMap) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) IndicesClient(org.elasticsearch.client.IndicesClient) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with GetAliasesResponse

use of org.elasticsearch.client.GetAliasesResponse in project herd by FINRAOS.

the class IndexFunctionsDaoTest method testCreateIndexDocumentsFunctionThrowsElasticsearchRestClientExceptionWhenBulkRequest.

@Test(expected = ElasticsearchRestClientException.class)
public void testCreateIndexDocumentsFunctionThrowsElasticsearchRestClientExceptionWhenBulkRequest() throws Exception {
    // Build mocks
    GetAliasesResponse getAliasesResponse = mock(GetAliasesResponse.class);
    IndicesClient indicesClient = mock(IndicesClient.class);
    RestHighLevelClient restHighLevelClient = mock(RestHighLevelClient.class);
    AliasMetadata AliasMetadata = mock(AliasMetadata.class);
    // Create objects needed for the test.
    Map<String, String> documentMap = new HashMap<>();
    documentMap.put(SEARCH_INDEX_DOCUMENT, SEARCH_INDEX_DOCUMENT_JSON);
    Set<AliasMetadata> AliasMetadataSet = new HashSet<>();
    AliasMetadataSet.add(AliasMetadata);
    Map<String, Set<AliasMetadata>> aliases = new HashMap<>();
    aliases.put(SEARCH_INDEX_ALIAS_BDEF, AliasMetadataSet);
    // Mock the calls to external methods
    when(elasticsearchRestHighLevelClientFactory.getRestHighLevelClient()).thenReturn(restHighLevelClient);
    when(restHighLevelClient.indices()).thenReturn(indicesClient);
    when(indicesClient.getAlias(any(GetAliasesRequest.class), eq(RequestOptions.DEFAULT))).thenReturn(getAliasesResponse);
    when(getAliasesResponse.getAliases()).thenReturn(aliases);
    when(restHighLevelClient.bulk(any(BulkRequest.class), eq(RequestOptions.DEFAULT))).thenThrow(new IOException());
    // Call the method under test
    indexFunctionsDao.createIndexDocuments(SEARCH_INDEX_NAME, documentMap);
}
Also used : AliasMetadata(org.elasticsearch.cluster.metadata.AliasMetadata) Set(java.util.Set) HashSet(java.util.HashSet) GetAliasesResponse(org.elasticsearch.client.GetAliasesResponse) HashMap(java.util.HashMap) IndicesClient(org.elasticsearch.client.IndicesClient) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) IOException(java.io.IOException) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

GetAliasesResponse (org.elasticsearch.client.GetAliasesResponse)17 GetAliasesRequest (org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)14 Set (java.util.Set)13 HashMap (java.util.HashMap)10 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)10 IndicesClient (org.elasticsearch.client.IndicesClient)10 RestHighLevelClient (org.elasticsearch.client.RestHighLevelClient)10 HashSet (java.util.HashSet)9 AliasMetadata (org.elasticsearch.cluster.metadata.AliasMetadata)9 Test (org.junit.Test)9 IOException (java.io.IOException)6 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)5 ArrayList (java.util.ArrayList)4 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)3 AcknowledgedResponse (org.elasticsearch.action.support.master.AcknowledgedResponse)3 ElasticException (io.hops.hopsworks.exceptions.ElasticException)2 GetAliasesRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)2 GetAliasesResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.GetAliasesResponse)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Duration (com.github.joschi.jadconfig.util.Duration)1