Search in sources :

Example 1 with IndexSettings

use of org.graylog2.indexer.indices.IndexSettings in project graylog2-server by Graylog2.

the class V20170607164210_MigrateReopenedIndicesToAliases method getReopenedIndices.

private Set<String> getReopenedIndices(final Collection<String> indices) {
    final SearchVersion elasticsearchVersion = node.getVersion().orElseThrow(() -> new ElasticsearchException("Unable to retrieve Elasticsearch version."));
    final JsonNode clusterStateJson = clusterState.getForIndices(indices);
    final JsonNode indicesJson = clusterStateJson.path("metadata").path("indices");
    final ImmutableSet.Builder<String> reopenedIndices = ImmutableSet.builder();
    if (indicesJson.isMissingNode()) {
        LOG.error("Retrieved cluster state is invalid (no metadata.indices key).");
        LOG.debug("Received cluster state was: {}", clusterStateJson.toString());
        return Collections.emptySet();
    }
    for (Iterator<Map.Entry<String, JsonNode>> it = indicesJson.fields(); it.hasNext(); ) {
        final Map.Entry<String, JsonNode> entry = it.next();
        final String indexName = entry.getKey();
        final JsonNode value = entry.getValue();
        final JsonNode indexSettings = value.path("settings");
        if (indexSettings.isMissingNode()) {
            LOG.error("Unable to retrieve index settings from metadata for index {} - skipping.", indexName);
            LOG.debug("Index metadata was: {}", value.toString());
            continue;
        }
        if (checkForReopened(indexSettings, elasticsearchVersion)) {
            LOG.debug("Adding {} to list of indices to be migrated.", indexName);
            reopenedIndices.add(indexName);
        }
    }
    return reopenedIndices.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) JsonNode(com.fasterxml.jackson.databind.JsonNode) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) SearchVersion(org.graylog2.storage.SearchVersion) Map(java.util.Map)

Example 2 with IndexSettings

use of org.graylog2.indexer.indices.IndexSettings in project graylog2-server by Graylog2.

the class IndicesAdapterES6 method create.

@Override
public void create(String indexName, IndexSettings indexSettings) {
    final Map<String, Object> settings = new HashMap<>();
    settings.put("number_of_shards", indexSettings.shards());
    settings.put("number_of_replicas", indexSettings.replicas());
    final CreateIndex request = new CreateIndex.Builder(indexName).settings(settings).build();
    final JestResult jestResult;
    try {
        jestResult = jestClient.execute(request);
    } catch (IOException e) {
        throw new ElasticsearchException("Couldn't create index " + indexName, e);
    }
    if (!jestResult.isSucceeded()) {
        throw new ElasticsearchException(jestResult.getErrorMessage());
    }
}
Also used : CreateIndex(io.searchbox.indices.CreateIndex) HashMap(java.util.HashMap) FieldSortBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.sort.FieldSortBuilder) SearchSourceBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder) FilterAggregationBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) IOException(java.io.IOException) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) JestResult(io.searchbox.client.JestResult)

Aggregations

ElasticsearchException (org.graylog2.indexer.ElasticsearchException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 JestResult (io.searchbox.client.JestResult)1 CreateIndex (io.searchbox.indices.CreateIndex)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FilterAggregationBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)1 SearchSourceBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder)1 FieldSortBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.sort.FieldSortBuilder)1 SearchVersion (org.graylog2.storage.SearchVersion)1