Search in sources :

Example 6 with RequestOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.

the class ClientES7 method resetIndexBlock.

@Override
public void resetIndexBlock(String index) {
    final UpdateSettingsRequest request = new UpdateSettingsRequest(index).settings(Collections.singletonMap("index.blocks.read_only_allow_delete", null));
    client.execute((c, requestOptions) -> c.indices().putSettings(request, requestOptions), "Unable to reset index block for " + index);
}
Also used : UpdateSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) ClusterUpdateSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)

Example 7 with RequestOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.

the class ClientES7 method bulkIndex.

@Override
public void bulkIndex(BulkIndexRequest bulkIndexRequest) {
    final BulkRequest bulkRequest = new BulkRequest();
    bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
    bulkIndexRequest.requests().forEach((indexName, documents) -> documents.forEach(doc -> bulkRequest.add(createIndexRequest(indexName, doc))));
    client.execute((c, requestOptions) -> c.bulk(bulkRequest, requestOptions));
}
Also used : ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) IndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest) Retryer(com.github.rholder.retry.Retryer) RetryerBuilder(com.github.rholder.retry.RetryerBuilder) LoggerFactory(org.slf4j.LoggerFactory) Callable(java.util.concurrent.Callable) WriteRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.WriteRequest) CloseIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CloseIndexRequest) ClusterHealthStatus(org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.health.ClusterHealthStatus) PutIndexTemplateRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutIndexTemplateRequest) GetIndexTemplatesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexTemplatesRequest) RefreshRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.refresh.RefreshRequest) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) AliasActions(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions) Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response) WaitStrategies(com.github.rholder.retry.WaitStrategies) GetIndexTemplatesResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexTemplatesResponse) GetIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexRequest) BulkIndexRequest(org.graylog.testing.elasticsearch.BulkIndexRequest) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DeleteIndexTemplateRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request) Client(org.graylog.testing.elasticsearch.Client) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Streams(com.google.common.collect.Streams) ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) Collectors(java.util.stream.Collectors) DeleteIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) CreateIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest) UpdateSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) TimeUnit(java.util.concurrent.TimeUnit) ClusterUpdateSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) Stream(java.util.stream.Stream) StopStrategies(com.github.rholder.retry.StopStrategies) Settings(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings) IndicesAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) BulkRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest) IndexTemplateMetadata(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.IndexTemplateMetadata) Collections(java.util.Collections) BulkRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest)

Example 8 with RequestOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.

the class FixtureImporterES7 method importNode.

private void importNode(JsonNode root) throws IOException {
    /* This supports the nosqlunit DataSet structure:
         *
         *  {
         *    "documents": [
         *      {
         *        "document": [
         *          {
         *            "index": {
         *              "indexName": "graylog_0",
         *              "indexId": "0"
         *            }
         *          },
         *          {
         *            "data": {
         *              "source": "example.org",
         *              "message": "Hi",
         *              "timestamp": "2015-01-01 01:00:00.000"
         *            }
         *          }
         *        ]
         *      }
         *    ]
         *  }
         */
    final BulkRequest bulkRequest = new BulkRequest();
    final Set<String> targetIndices = new HashSet<>();
    for (final JsonNode document : root.path("documents")) {
        final List<JsonNode> indexes = new ArrayList<>();
        Map<String, Object> data = new HashMap<>();
        for (JsonNode entry : document.path("document")) {
            if (entry.hasNonNull("index")) {
                indexes.add(entry.path("index"));
            } else if (entry.hasNonNull("data")) {
                data = OBJECT_MAPPER.convertValue(entry.path("data"), TypeReferences.MAP_STRING_OBJECT);
            }
        }
        for (final JsonNode index : indexes) {
            final IndexRequest indexRequest = new IndexRequest().source(data);
            final String indexName = index.path("indexName").asText(null);
            if (indexName == null) {
                throw new IllegalArgumentException("Missing indexName in " + index);
            }
            targetIndices.add(indexName);
            indexRequest.index(indexName);
            if (index.hasNonNull("indexId")) {
                indexRequest.id(index.path("indexId").asText());
            }
            bulkRequest.add(indexRequest);
        }
    }
    for (String indexName : targetIndices) {
        if (!indexExists(indexName)) {
            createIndex(indexName);
        }
    }
    final BulkResponse result = client.execute((c, requestOptions) -> c.bulk(bulkRequest, requestOptions), "Unable to import fixtures.");
    if (result.hasFailures()) {
        throw new IllegalStateException("Error while bulk indexing documents: " + result.buildFailureMessage());
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) BulkResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkResponse) GetIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexRequest) IndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest) CreateIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest) BulkRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest) HashSet(java.util.HashSet)

Example 9 with RequestOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.

the class MessagesES7IT method indexMessage.

@Override
protected boolean indexMessage(String index, Map<String, Object> source, String id) {
    final IndexRequest indexRequest = new IndexRequest(index).source(source).id(id);
    final IndexResponse result = this.elasticsearch.elasticsearchClient().execute((c, requestOptions) -> c.index(indexRequest, requestOptions));
    return result.status().equals(RestStatus.CREATED);
}
Also used : IndexResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse) IndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest)

Example 10 with RequestOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.

the class ElasticsearchClient method msearch.

public List<MultiSearchResponse.Item> msearch(List<SearchRequest> searchRequests, String errorMessage) {
    final MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
    searchRequests.forEach(multiSearchRequest::add);
    final MultiSearchResponse result = this.execute((c, requestOptions) -> c.msearch(multiSearchRequest, requestOptions), errorMessage);
    return Streams.stream(result).collect(Collectors.toList());
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) MultiSearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchRequest)

Aggregations

IndicesAliasesRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)8 CreateIndexRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest)8 Collectors (java.util.stream.Collectors)7 ClusterHealthRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)7 Request (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)7 Inject (javax.inject.Inject)6 DeleteIndexRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)6 UpdateSettingsRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest)6 DeleteIndexTemplateRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)6 IndexRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest)6 PutIndexTemplateRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutIndexTemplateRequest)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Collection (java.util.Collection)5 List (java.util.List)5 Map (java.util.Map)5 ClusterUpdateSettingsRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)5 BulkRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest)5 ElasticsearchClient (org.graylog.storage.elasticsearch7.ElasticsearchClient)5