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;
}
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);
}
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);
}
}
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();
}
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);
}
Aggregations