Search in sources :

Example 1 with ModifyAliases

use of io.searchbox.indices.aliases.ModifyAliases in project graylog2-server by Graylog2.

the class ClientES6 method addAliasMapping.

@Override
public void addAliasMapping(String indexName, String alias) {
    final AddAliasMapping addAliasMapping = new AddAliasMapping.Builder(indexName, alias).build();
    final ModifyAliases addAliasRequest = new ModifyAliases.Builder(addAliasMapping).build();
    executeWithExpectedSuccess(addAliasRequest, "failed to add alias " + alias + " for index " + indexName);
}
Also used : AddAliasMapping(io.searchbox.indices.aliases.AddAliasMapping) ModifyAliases(io.searchbox.indices.aliases.ModifyAliases)

Example 2 with ModifyAliases

use of io.searchbox.indices.aliases.ModifyAliases in project graylog2-server by Graylog2.

the class IndicesAdapterES6 method cycleAlias.

@Override
public void cycleAlias(String aliasName, String targetIndex, String oldIndex) {
    final AliasMapping addAliasMapping = new AddAliasMapping.Builder(targetIndex, aliasName).build();
    final AliasMapping removeAliasMapping = new RemoveAliasMapping.Builder(oldIndex, aliasName).build();
    final ModifyAliases request = new ModifyAliases.Builder(Arrays.asList(removeAliasMapping, addAliasMapping)).build();
    JestUtils.execute(jestClient, request, () -> "Couldn't switch alias " + aliasName + " from index " + oldIndex + " to index " + targetIndex);
}
Also used : AddAliasMapping(io.searchbox.indices.aliases.AddAliasMapping) RemoveAliasMapping(io.searchbox.indices.aliases.RemoveAliasMapping) AliasMapping(io.searchbox.indices.aliases.AliasMapping) AddAliasMapping(io.searchbox.indices.aliases.AddAliasMapping) ModifyAliases(io.searchbox.indices.aliases.ModifyAliases) RemoveAliasMapping(io.searchbox.indices.aliases.RemoveAliasMapping)

Example 3 with ModifyAliases

use of io.searchbox.indices.aliases.ModifyAliases in project herd by FINRAOS.

the class IndexFunctionsDaoImpl method createIndex.

/**
 * The create index function will take as arguments the index name, document type, and mapping and will create a new index.
 */
@Override
public final void createIndex(String indexName, String documentType, String mapping, String settings, String alias) {
    LOGGER.info("Creating Elasticsearch index, indexName={}, documentType={}.", indexName, documentType);
    CreateIndex createIndex = new CreateIndex.Builder(indexName).settings(Settings.builder().loadFromSource(settings).build()).build();
    PutMapping putMapping = new PutMapping.Builder(indexName, documentType, mapping).build();
    ModifyAliases modifyAliases = new ModifyAliases.Builder(new AddAliasMapping.Builder(indexName, alias).build()).build();
    JestResult jestResult = jestClientHelper.executeAction(createIndex);
    LOGGER.info("Creating Elasticsearch index, indexName={}, documentType={} successful={}", indexName, documentType, jestResult.isSucceeded());
    jestResult = jestClientHelper.executeAction(putMapping);
    LOGGER.info("Creating Elasticsearch index put mappings, indexName={}, documentType={} successful={}", indexName, documentType, jestResult.isSucceeded());
    jestResult = jestClientHelper.executeAction(modifyAliases);
    LOGGER.info("Creating Elasticsearch index alias, indexName={}, alias={}", indexName, alias, jestResult.isSucceeded());
    // If there are failures log them
    if (!jestResult.isSucceeded()) {
        LOGGER.error("Error in index creation= {}", jestResult.getErrorMessage());
    }
}
Also used : CreateIndex(io.searchbox.indices.CreateIndex) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) PutMapping(io.searchbox.indices.mapping.PutMapping) ModifyAliases(io.searchbox.indices.aliases.ModifyAliases) AddAliasMapping(io.searchbox.indices.aliases.AddAliasMapping) JestResult(io.searchbox.client.JestResult)

Example 4 with ModifyAliases

use of io.searchbox.indices.aliases.ModifyAliases in project graylog2-server by Graylog2.

the class IndicesAdapterES6 method removeAliases.

@Override
public void removeAliases(Set<String> indices, String alias) {
    final AliasMapping removeAliasMapping = new RemoveAliasMapping.Builder(ImmutableList.copyOf(indices), alias).build();
    final ModifyAliases request = new ModifyAliases.Builder(removeAliasMapping).build();
    JestUtils.execute(jestClient, request, () -> "Couldn't remove alias " + alias + " from indices " + indices);
}
Also used : AddAliasMapping(io.searchbox.indices.aliases.AddAliasMapping) RemoveAliasMapping(io.searchbox.indices.aliases.RemoveAliasMapping) AliasMapping(io.searchbox.indices.aliases.AliasMapping) ModifyAliases(io.searchbox.indices.aliases.ModifyAliases) RemoveAliasMapping(io.searchbox.indices.aliases.RemoveAliasMapping)

Example 5 with ModifyAliases

use of io.searchbox.indices.aliases.ModifyAliases in project graylog2-server by Graylog2.

the class IndicesAdapterES6 method markIndexReopened.

@Override
public void markIndexReopened(String index) {
    final String aliasName = index + Indices.REOPENED_ALIAS_SUFFIX;
    final ModifyAliases request = new ModifyAliases.Builder(new AddAliasMapping.Builder(index, aliasName).build()).build();
    JestUtils.execute(jestClient, request, () -> "Couldn't create reopened alias for index " + index);
}
Also used : ModifyAliases(io.searchbox.indices.aliases.ModifyAliases) AddAliasMapping(io.searchbox.indices.aliases.AddAliasMapping)

Aggregations

ModifyAliases (io.searchbox.indices.aliases.ModifyAliases)6 AddAliasMapping (io.searchbox.indices.aliases.AddAliasMapping)5 RemoveAliasMapping (io.searchbox.indices.aliases.RemoveAliasMapping)3 AliasMapping (io.searchbox.indices.aliases.AliasMapping)2 JestResult (io.searchbox.client.JestResult)1 CreateIndex (io.searchbox.indices.CreateIndex)1 PutMapping (io.searchbox.indices.mapping.PutMapping)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)1