Search in sources :

Example 6 with CreateIndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest in project ranger by apache.

the class ElasticSearchIndexBootStrapper method createIndex.

private boolean createIndex() {
    boolean exits = false;
    if (client == null) {
        connect();
    }
    if (client != null) {
        try {
            exits = client.indices().open(new OpenIndexRequest(this.index), RequestOptions.DEFAULT).isShardsAcknowledged();
        } catch (Exception e) {
            LOG.info("Index " + this.index + " not available.");
        }
        if (!exits) {
            LOG.info("Index does not exist. Attempting to create index:" + this.index);
            CreateIndexRequest request = new CreateIndexRequest(this.index);
            if (this.no_of_shards >= 0 && this.no_of_replicas >= 0) {
                request.settings(Settings.builder().put("index.number_of_shards", this.no_of_shards).put("index.number_of_replicas", this.no_of_replicas));
            }
            request.mapping(es_ranger_audit_schema_json, XContentType.JSON);
            request.setMasterTimeout(TimeValue.timeValueMinutes(1));
            request.setTimeout(TimeValue.timeValueMinutes(2));
            try {
                CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
                if (createIndexResponse != null) {
                    exits = client.indices().open(new OpenIndexRequest(this.index), RequestOptions.DEFAULT).isShardsAcknowledged();
                    if (exits) {
                        LOG.info("Index " + this.index + " created successfully.");
                    }
                }
            } catch (Exception e) {
                LOG.severe("Unable to create Index. Reason:" + e.toString());
                e.printStackTrace();
            }
        } else {
            LOG.info("Index " + this.index + " is already created.");
        }
    }
    return exits;
}
Also used : OpenIndexRequest(org.elasticsearch.action.admin.indices.open.OpenIndexRequest) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) CreateIndexResponse(org.elasticsearch.client.indices.CreateIndexResponse) IOException(java.io.IOException)

Example 7 with CreateIndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest in project vorto by eclipse.

the class ElasticSearchService method createIndexRequest.

private IndexRequest createIndexRequest(ModelInfo modelInfo, String tenantId) {
    Map<String, Object> jsonMap = new HashMap<>();
    jsonMap.put(TENANT_ID, tenantId);
    for (IIndexFieldExtractor extractor : fieldExtractors) {
        extractor.extractFields(modelInfo).forEach((key, value) -> {
            jsonMap.put(key, value);
        });
    }
    return new IndexRequest(VORTO_INDEX, DOC, modelInfo.getId().getPrettyFormat()).source(jsonMap);
}
Also used : IIndexFieldExtractor(org.eclipse.vorto.repository.search.extractor.IIndexFieldExtractor) IndexRequest(org.elasticsearch.action.index.IndexRequest) GetIndexRequest(org.elasticsearch.client.indices.GetIndexRequest) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest)

Example 8 with CreateIndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest in project vorto by eclipse.

the class ElasticSearchService method createIndexWithMapping.

private boolean createIndexWithMapping(String index, Map<String, Object> mapping) {
    CreateIndexRequest request = new CreateIndexRequest(index);
    request.mapping(mapping);
    try {
        CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
        return createIndexResponse.isAcknowledged();
    } catch (IOException e) {
        throw new IndexingException("Error while creating index '" + index + "'.", e);
    }
}
Also used : IOException(java.io.IOException) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) CreateIndexResponse(org.elasticsearch.client.indices.CreateIndexResponse)

Example 9 with CreateIndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest in project chili-core by codingchili.

the class ElasticMap method createIndexIfNotExists.

private Future<Void> createIndexIfNotExists() {
    Promise<Void> promise = Promise.promise();
    context.blocking((done) -> {
        IndicesClient indices = client.indices();
        try {
            var exists = indices.exists(new GetIndexRequest(index), RequestOptions.DEFAULT);
            if (!exists) {
                var request = new CreateIndexRequest(index);
                configureMapping(request);
                configureSettings(request);
                indices.create(request, RequestOptions.DEFAULT);
            }
            done.complete();
        } catch (Throwable e) {
            done.fail(e);
        }
    }, promise);
    return promise.future();
}
Also used : GetIndexRequest(org.elasticsearch.client.indices.GetIndexRequest) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest)

Example 10 with CreateIndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest in project hazelcast by hazelcast.

the class BaseElasticTest method createShardedIndex.

/**
 * Creates an index with given name with 3 shards
 */
protected void createShardedIndex(String index, int shards, int replicas) throws IOException {
    CreateIndexRequest indexRequest = new CreateIndexRequest(index);
    indexRequest.settings(Settings.builder().put("index.unassigned.node_left.delayed_timeout", "1s").put("index.number_of_shards", shards).put("index.number_of_replicas", replicas));
    elasticClient.indices().create(indexRequest, RequestOptions.DEFAULT);
}
Also used : CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest)

Aggregations

CreateIndexRequest (org.elasticsearch.client.indices.CreateIndexRequest)17 IOException (java.io.IOException)6 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)6 IndexRequest (org.elasticsearch.action.index.IndexRequest)5 GetIndexRequest (org.elasticsearch.client.indices.GetIndexRequest)5 RefreshRequest (org.elasticsearch.action.admin.indices.refresh.RefreshRequest)4 RestHighLevelClient (org.elasticsearch.client.RestHighLevelClient)4 CreateIndexResponse (org.elasticsearch.client.indices.CreateIndexResponse)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)4 CreateIndexRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AcknowledgedResponse (org.elasticsearch.action.support.master.AcknowledgedResponse)2 DocumentMapping (com.b2international.index.mapping.DocumentMapping)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Retryer (com.github.rholder.retry.Retryer)1 RetryerBuilder (com.github.rholder.retry.RetryerBuilder)1 StopStrategies (com.github.rholder.retry.StopStrategies)1