Search in sources :

Example 1 with IndicesAdminClient

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

the class Indices method aliasTarget.

@Nullable
public String aliasTarget(String alias) throws TooManyAliasesException {
    final IndicesAdminClient indicesAdminClient = c.admin().indices();
    final GetAliasesRequest request = indicesAdminClient.prepareGetAliases(alias).request();
    final GetAliasesResponse response = indicesAdminClient.getAliases(request).actionGet();
    // The ES return value of this has an awkward format: The first key of the hash is the target index. Thanks.
    final ImmutableOpenMap<String, List<AliasMetaData>> aliases = response.getAliases();
    if (aliases.size() > 1) {
        throw new TooManyAliasesException(Sets.newHashSet(aliases.keysIt()));
    }
    return aliases.isEmpty() ? null : aliases.keysIt().next();
}
Also used : GetAliasesResponse(org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Nullable(javax.annotation.Nullable)

Example 2 with IndicesAdminClient

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

the class IndicesTest method testAliasTarget.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testAliasTarget() throws Exception {
    assertThat(indices.aliasTarget("graylog_alias")).isNull();
    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.aliasTarget("graylog_alias")).isEqualTo(INDEX_NAME);
}
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 3 with IndicesAdminClient

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

the class IndicesTest method testIndexTemplateCanBeOverridden.

@Test
public void testIndexTemplateCanBeOverridden() throws Exception {
    final String customTemplateName = "custom-template";
    final IndicesAdminClient client = this.client.admin().indices();
    // Create custom index template
    final Map<String, Object> customMapping = ImmutableMap.of("_source", ImmutableMap.of("enabled", false), "properties", ImmutableMap.of("message", ImmutableMap.of("type", "string", "index", "not_analyzed")));
    final PutIndexTemplateResponse putIndexTemplateResponse = client.preparePutTemplate(customTemplateName).setTemplate(indexSet.getIndexWildcard()).setOrder(1).addMapping(IndexMapping.TYPE_MESSAGE, customMapping).get();
    assertThat(putIndexTemplateResponse.isAcknowledged()).isTrue();
    // Validate existing index templates
    final GetIndexTemplatesResponse getTemplatesResponse = client.prepareGetTemplates().get();
    final List<IndexTemplateMetaData> indexTemplates = getTemplatesResponse.getIndexTemplates();
    assertThat(indexTemplates).extracting(IndexTemplateMetaData::getName).containsExactly(customTemplateName);
    // Create index with custom template
    final String testIndexName = "graylog_override_template";
    indices.create(testIndexName, indexSet);
    // Check index mapping
    final GetMappingsResponse indexMappingResponse = client.prepareGetMappings(testIndexName).get();
    final String mapping = indexMappingResponse.getMappings().get(testIndexName).get(IndexMapping.TYPE_MESSAGE).source().string();
    final ReadContext ctx = JsonPath.parse(mapping);
    final boolean sourceEnabled = ctx.read("$.message._source.enabled");
    assertThat(sourceEnabled).isFalse();
    final String messageField = ctx.read("$.message.properties.message.index");
    assertThat(messageField).isEqualTo("not_analyzed");
    // Clean up
    final DeleteIndexTemplateResponse deleteResponse = client.prepareDeleteTemplate(customTemplateName).get();
    assertThat(deleteResponse.isAcknowledged()).isTrue();
    indices.delete(testIndexName);
}
Also used : DeleteIndexTemplateResponse(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) ReadContext(com.jayway.jsonpath.ReadContext) PutIndexTemplateResponse(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse) Test(org.junit.Test)

Example 4 with IndicesAdminClient

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

the class IndicesTest method testCreateEnsuresIndexTemplateExists.

@Test
public void testCreateEnsuresIndexTemplateExists() throws Exception {
    final String templateName = indexSetConfig.indexTemplateName();
    final IndicesAdminClient client = this.client.admin().indices();
    final GetIndexTemplatesRequest request = client.prepareGetTemplates(templateName).request();
    final GetIndexTemplatesResponse responseBefore = client.getTemplates(request).actionGet();
    assertThat(responseBefore.getIndexTemplates()).isEmpty();
    indices.create("index_template_test", indexSet);
    final GetIndexTemplatesResponse responseAfter = client.getTemplates(request).actionGet();
    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 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) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) GetIndexTemplatesRequest(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) Test(org.junit.Test)

Example 5 with IndicesAdminClient

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

the class AdminUpgradeAction method upgradeFrom11_1.

private void upgradeFrom11_1() {
    final IndicesAdminClient indicesClient = fessEsClient.admin().indices();
    final String configIndex = ".fess_config";
    // update mapping
    addFieldMapping(indicesClient, configIndex, "thumbnail_queue", "thumbnail_id", "{\"properties\":{\"thumbnail_id\":{\"type\":\"keyword\"}}}");
}
Also used : IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient)

Aggregations

IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)27 IndicesExistsResponse (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse)6 Test (org.junit.Test)6 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)4 IndicesAliasesResponse (org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse)3 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)3 DeleteIndexTemplateResponse (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse)3 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)3 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)3 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 IndicesAliasesRequest (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)2 GetAliasesResponse (org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse)2 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)2 IndicesExistsRequest (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)2 GetIndexResponse (org.elasticsearch.action.admin.indices.get.GetIndexResponse)2 GetMappingsResponse (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)2