Search in sources :

Example 1 with FIELD_GL2_MESSAGE_ID

use of org.graylog2.plugin.Message.FIELD_GL2_MESSAGE_ID in project graylog2-server by Graylog2.

the class V20200730000000_AddGl2MessageIdFieldAliasForEventsES7 method addGl2MessageIdFieldAlias.

@Override
public void addGl2MessageIdFieldAlias(Set<String> indexPrefixes) {
    final String[] prefixesWithWildcard = indexPrefixes.stream().map(p -> p + "*").toArray(String[]::new);
    final PutMappingRequest putMappingRequest = new PutMappingRequest(prefixesWithWildcard).indicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED).source(ImmutableMap.of("properties", ImmutableMap.of(FIELD_GL2_MESSAGE_ID, aliasMapping())));
    try {
        final AcknowledgedResponse acknowledgedResponse = client.execute((c, requestOptions) -> c.indices().putMapping(putMappingRequest, requestOptions));
        if (!acknowledgedResponse.isAcknowledged()) {
            throw new ElasticsearchException(errorMsgFor(prefixesWithWildcard) + " Elasticsearch failed to acknowledge.");
        }
    } catch (ElasticsearchException e) {
        throw new ElasticsearchException(errorMsgFor(prefixesWithWildcard), e);
    }
}
Also used : Inject(javax.inject.Inject) LinkedHashMap(java.util.LinkedHashMap) V20200730000000_AddGl2MessageIdFieldAliasForEvents(org.graylog.plugins.views.migrations.V20200730000000_AddGl2MessageIdFieldAliasForEvents) PutMappingRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutMappingRequest) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) Arrays(java.util.Arrays) ImmutableMap(com.google.common.collect.ImmutableMap) IndicesOptions(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions) AcknowledgedResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse) Set(java.util.Set) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) FIELD_GL2_MESSAGE_ID(org.graylog2.plugin.Message.FIELD_GL2_MESSAGE_ID) PutMappingRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutMappingRequest) AcknowledgedResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse) ElasticsearchException(org.graylog2.indexer.ElasticsearchException)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Arrays (java.util.Arrays)1 LinkedHashMap (java.util.LinkedHashMap)1 Set (java.util.Set)1 Inject (javax.inject.Inject)1 V20200730000000_AddGl2MessageIdFieldAliasForEvents (org.graylog.plugins.views.migrations.V20200730000000_AddGl2MessageIdFieldAliasForEvents)1 IndicesOptions (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions)1 AcknowledgedResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse)1 PutMappingRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutMappingRequest)1 ElasticsearchClient (org.graylog.storage.elasticsearch7.ElasticsearchClient)1 ElasticsearchException (org.graylog2.indexer.ElasticsearchException)1 FIELD_GL2_MESSAGE_ID (org.graylog2.plugin.Message.FIELD_GL2_MESSAGE_ID)1