use of org.elasticsearch.client.indices.GetIndexRequest in project sonarqube by SonarSource.
the class IndexCreator method start.
@Override
public void start() {
// create the "metadata" index first
IndexType.IndexMainType metadataMainType = TYPE_METADATA;
if (!client.indexExists(new GetIndexRequest(metadataMainType.getIndex().getName()))) {
IndexDefinition.IndexDefinitionContext context = new IndexDefinition.IndexDefinitionContext();
metadataIndexDefinition.define(context);
NewIndex index = context.getIndices().values().iterator().next();
createIndex(index.build(), false);
} else {
ensureWritable(metadataMainType);
}
checkDbCompatibility(definitions.getIndices().values());
// create indices that do not exist or that have a new definition (different mapping, cluster enabled, ...)
definitions.getIndices().values().stream().filter(i -> !i.getMainType().equals(metadataMainType)).forEach(index -> {
boolean exists = client.indexExists(new GetIndexRequest(index.getMainType().getIndex().getName()));
if (!exists) {
createIndex(index, true);
} else if (hasDefinitionChange(index)) {
updateIndex(index);
} else {
ensureWritable(index.getMainType());
}
});
}
use of org.elasticsearch.client.indices.GetIndexRequest 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.elasticsearch.client.indices.GetIndexRequest in project datashare by ICIJ.
the class ElasticsearchConfiguration method createIndex.
public static boolean createIndex(RestHighLevelClient client, String indexName) {
GetIndexRequest request = new GetIndexRequest(indexName);
try {
if (!client.indices().exists(request, RequestOptions.DEFAULT)) {
LOGGER.info("index {} does not exist, creating one", indexName);
CreateIndexRequest createReq = new CreateIndexRequest(indexName);
createReq.settings(getResourceContent(SETTINGS_RESOURCE_NAME), JSON);
createReq.mapping(getResourceContent(MAPPING_RESOURCE_NAME), JSON);
client.indices().create(createReq, RequestOptions.DEFAULT);
return true;
}
} catch (IOException e) {
throw new ConfigurationException(e);
}
return false;
}
use of org.elasticsearch.client.indices.GetIndexRequest in project datashare by ICIJ.
the class ElasticsearchRule method before.
@Override
protected void before() throws Throwable {
GetIndexRequest request = new GetIndexRequest(indexName);
if (!client.indices().exists(request, RequestOptions.DEFAULT)) {
CreateIndexRequest createReq = new CreateIndexRequest(indexName);
byte[] settings = toByteArray(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(SETTINGS_RESOURCE_NAME)));
createReq.settings(new String(settings), JSON);
byte[] mapping = toByteArray(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(MAPPING_RESOURCE_NAME)));
createReq.mapping(new String(mapping), JSON);
client.indices().create(createReq, RequestOptions.DEFAULT);
}
}
Aggregations