Search in sources :

Example 6 with IndicesAdminClient

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

the class IndicesTest method testCreateOverwritesIndexTemplate.

@Test
public void testCreateOverwritesIndexTemplate() throws Exception {
    final ObjectMapper mapper = new ObjectMapperProvider().get();
    final String templateName = indexSetConfig.indexTemplateName();
    final IndicesAdminClient client = this.client.admin().indices();
    final ImmutableMap<String, Object> beforeMapping = ImmutableMap.of("_source", ImmutableMap.of("enabled", false), "properties", ImmutableMap.of("message", ImmutableMap.of("type", "string", "index", "not_analyzed")));
    assertThat(client.preparePutTemplate(templateName).setTemplate(indexSet.getIndexWildcard()).addMapping(IndexMapping.TYPE_MESSAGE, beforeMapping).get().isAcknowledged()).isTrue();
    final GetIndexTemplatesResponse responseBefore = client.prepareGetTemplates(templateName).get();
    final List<IndexTemplateMetaData> beforeIndexTemplates = responseBefore.getIndexTemplates();
    assertThat(beforeIndexTemplates).hasSize(1);
    final ImmutableOpenMap<String, CompressedXContent> beforeMappings = beforeIndexTemplates.get(0).getMappings();
    final Map<String, Object> actualMapping = mapper.readValue(beforeMappings.get(IndexMapping.TYPE_MESSAGE).uncompressed(), new TypeReference<Map<String, Object>>() {
    });
    assertThat(actualMapping.get(IndexMapping.TYPE_MESSAGE)).isEqualTo(beforeMapping);
    indices.create("index_template_test", indexSet);
    final GetIndexTemplatesResponse responseAfter = client.prepareGetTemplates(templateName).get();
    assertThat(responseAfter.getIndexTemplates()).hasSize(1);
    final IndexTemplateMetaData templateMetaData = responseAfter.getIndexTemplates().get(0);
    assertThat(templateMetaData.getName()).isEqualTo(templateName);
    assertThat(templateMetaData.getMappings().keysIt()).containsExactly(IndexMapping.TYPE_MESSAGE);
    final Map<String, Object> mapping = mapper.readValue(templateMetaData.getMappings().get(IndexMapping.TYPE_MESSAGE).uncompressed(), new TypeReference<Map<String, Object>>() {
    });
    final Map<String, Object> expectedTemplate = new IndexMapping().messageTemplate(indexSet.getIndexWildcard(), indexSetConfig.indexAnalyzer());
    assertThat(mapping).isEqualTo(expectedTemplate.get("mappings"));
    final DeleteIndexTemplateRequest deleteRequest = client.prepareDeleteTemplate(templateName).request();
    final DeleteIndexTemplateResponse deleteResponse = client.deleteTemplate(deleteRequest).actionGet();
    assertThat(deleteResponse.isAcknowledged()).isTrue();
    indices.delete("index_template_test");
}
Also used : DeleteIndexTemplateResponse(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) IndexMapping(org.graylog2.indexer.IndexMapping) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 7 with IndicesAdminClient

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

the class IndicesTest method testAliasExists.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testAliasExists() throws Exception {
    assertThat(indices.aliasExists("graylog_alias")).isFalse();
    final IndicesAdminClient adminClient = client.admin().indices();
    final IndicesAliasesRequest request = adminClient.prepareAliases().addAlias(INDEX_NAME, "graylog_alias").request();
    final IndicesAliasesResponse response = adminClient.aliases(request).actionGet(ES_TIMEOUT);
    assertThat(response.isAcknowledged()).isTrue();
    assertThat(indices.aliasExists("graylog_alias")).isTrue();
}
Also used : IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) IndicesAliasesResponse(org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 8 with IndicesAdminClient

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

the class IndexCreatingDatabaseOperation method insert.

@Override
public void insert(InputStream dataScript) {
    waitForGreenStatus();
    final IndicesAdminClient indicesAdminClient = client.admin().indices();
    for (String index : indexes) {
        final IndicesExistsResponse indicesExistsResponse = indicesAdminClient.prepareExists(index).execute().actionGet();
        if (indicesExistsResponse.isExists()) {
            client.admin().indices().prepareDelete(index).execute().actionGet();
        }
        final Messages messages = new Messages(client, new MetricRegistry());
        final Indices indices = new Indices(client, new IndexMapping(), messages, mock(NodeId.class), new NullAuditEventSender());
        if (!indices.create(index, indexSet)) {
            throw new IllegalStateException("Couldn't create index " + index);
        }
    }
    databaseOperation.insert(dataScript);
}
Also used : NullAuditEventSender(org.graylog2.audit.NullAuditEventSender) IndexMapping(org.graylog2.indexer.IndexMapping) Messages(org.graylog2.indexer.messages.Messages) MetricRegistry(com.codahale.metrics.MetricRegistry) IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) NodeId(org.graylog2.plugin.system.NodeId) Indices(org.graylog2.indexer.indices.Indices) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient)

Example 9 with IndicesAdminClient

use of org.elasticsearch.client.IndicesAdminClient in project beam by apache.

the class ElasticSearchIOTestUtils method deleteIndex.

/** Deletes the given index synchronously. */
static void deleteIndex(String index, Client client) throws Exception {
    IndicesAdminClient indices = client.admin().indices();
    IndicesExistsResponse indicesExistsResponse = indices.exists(new IndicesExistsRequest(index)).get();
    if (indicesExistsResponse.isExists()) {
        indices.prepareClose(index).get();
        indices.delete(Requests.deleteIndexRequest(index)).get();
    }
}
Also used : IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)

Example 10 with IndicesAdminClient

use of org.elasticsearch.client.IndicesAdminClient in project fess by codelibs.

the class AdminUpgradeAction method upgradeFromAll.

private void upgradeFromAll() {
    final IndicesAdminClient indicesClient = fessEsClient.admin().indices();
    final String crawlerIndex = fessConfig.getIndexDocumentCrawlerIndex();
    // .crawler
    if (existsIndex(indicesClient, crawlerIndex, IndicesOptions.fromOptions(false, true, true, true))) {
        deleteIndex(indicesClient, crawlerIndex, response -> {
        });
    }
}
Also used : IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient)

Aggregations

IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)11 Test (org.junit.Test)5 IndicesExistsResponse (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse)3 DeleteIndexTemplateResponse (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse)3 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)3 IndexTemplateMetaData (org.elasticsearch.cluster.metadata.IndexTemplateMetaData)3 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 IndicesAliasesRequest (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)2 IndicesAliasesResponse (org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse)2 DeleteIndexTemplateRequest (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)2 IndexMapping (org.graylog2.indexer.IndexMapping)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ReadContext (com.jayway.jsonpath.ReadContext)1 List (java.util.List)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 GetAliasesRequest (org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)1