use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project vertexium by visallo.
the class Elasticsearch5SearchIndex method createIndex.
@SuppressWarnings("unused")
protected void createIndex(String indexName) throws IOException {
CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName).setSettings(XContentFactory.jsonBuilder().startObject().startObject("analysis").startObject("normalizer").startObject(LOWERCASER_NORMALIZER_NAME).field("type", "custom").array("filter", "lowercase").endObject().endObject().endObject().field("number_of_shards", getConfig().getNumberOfShards()).field("number_of_replicas", getConfig().getNumberOfReplicas()).field("index.mapping.total_fields.limit", getConfig().getIndexMappingTotalFieldsLimit()).field("refresh_interval", getConfig().getIndexRefreshInterval()).endObject()).execute().actionGet();
ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName).setWaitForGreenStatus().execute().actionGet();
LOGGER.debug("Index status: %s", health.toString());
if (health.isTimedOut()) {
LOGGER.warn("timed out waiting for yellow/green index status, for index: %s", indexName);
}
}
use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project vertexium by visallo.
the class Elasticsearch7SearchIndex method createIndex.
@SuppressWarnings("unused")
protected void createIndex(String indexName) throws IOException {
CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName).setSettings(XContentFactory.jsonBuilder().startObject().startObject("analysis").startObject("normalizer").startObject(LOWERCASER_NORMALIZER_NAME).field("type", "custom").array("filter", "lowercase").endObject().endObject().endObject().field("number_of_shards", getConfig().getNumberOfShards()).field("number_of_replicas", getConfig().getNumberOfReplicas()).field("index.mapping.total_fields.limit", getConfig().getIndexMappingTotalFieldsLimit()).field("refresh_interval", getConfig().getIndexRefreshInterval()).endObject()).execute().actionGet();
ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName).setWaitForGreenStatus().execute().actionGet();
LOGGER.debug("Index status: %s", health.toString());
if (health.isTimedOut()) {
LOGGER.warn("timed out waiting for yellow/green index status, for index: %s", indexName);
}
}
use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project ccd-definition-store-api by hmcts.
the class HighLevelCCDElasticClient method createIndex.
@Override
public boolean createIndex(String indexName, String alias) throws IOException {
log.info("creating index {} with alias {}", indexName, alias);
CreateIndexRequest request = new CreateIndexRequest(indexName);
request.alias(new Alias(alias));
String file = (alias.equalsIgnoreCase(GLOBAL_SEARCH)) ? GLOBAL_SEARCH_CASES_INDEX_SETTINGS_JSON : CASES_INDEX_SETTINGS_JSON;
request.settings(casesIndexSettings(file));
CreateIndexResponse createIndexResponse = elasticClient.indices().create(request, RequestOptions.DEFAULT);
log.info("index created: {}", createIndexResponse.isAcknowledged());
return createIndexResponse.isAcknowledged();
}
use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project c2mon by c2mon.
the class ElasticsearchClientTransport method createIndex.
@Override
public boolean createIndex(IndexMetadata indexMetadata, String mapping) {
CreateIndexRequestBuilder builder = client.admin().indices().prepareCreate(indexMetadata.getName());
builder.setSettings(Settings.builder().put("number_of_shards", properties.getShardsPerIndex()).put("number_of_replicas", properties.getReplicasPerShard()).build());
if (mapping != null) {
builder.addMapping(mapping, XContentType.JSON);
}
log.debug("Creating new index with name {}", indexMetadata.getName());
try {
CreateIndexResponse response = builder.get();
return response.isAcknowledged();
} catch (ResourceAlreadyExistsException e) {
log.debug("Index already exists.", e);
}
return false;
}
use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project cdap by cdapio.
the class ElasticsearchMetadataStorage method createIndex.
@Override
public void createIndex() throws IOException {
if (created) {
return;
}
synchronized (this) {
if (created) {
return;
}
GetIndexRequest request = new GetIndexRequest();
request.indices(indexName);
RestHighLevelClient client = getClient();
if (!client.indices().exists(request, RequestOptions.DEFAULT)) {
String settings = createSettings();
LOG.info("Creating index '{}' with settings: {}", indexName, settings);
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
createIndexRequest.settings(settings, XContentType.JSON);
createIndexRequest.mapping(DOC_TYPE, createMappings(), XContentType.JSON);
CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
if (!response.isAcknowledged()) {
throw new IOException("Create index request was not acknowledged by EleasticSearch: " + response);
}
}
request = new GetIndexRequest();
request.indices(indexName);
GetIndexResponse response = client.indices().get(request, RequestOptions.DEFAULT);
Settings settings = response.getSettings().get(indexName);
if (settings == null) {
throw new IOException("Unable to obtain Elasticsearch settings for index " + indexName);
}
String maxWindow = response.getSetting(indexName, "index.max_result_window");
if (maxWindow != null) {
maxWindowSize = Integer.parseInt(maxWindow);
}
LOG.debug("Using Elasticsearch index {} with 'max_result_window' of {}", indexName, maxWindowSize);
// For some unknown reason, multi-get fails immediately after creating an index
// However, performing one regular read appears to fix that, perhaps it waits until the index is ready?
// Hence, perform one read to ensure the index is ready to use.
readFromIndex(MetadataEntity.ofNamespace("system"));
created = true;
}
}
Aggregations