use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project graylog2-server by Graylog2.
the class IndicesGetAllMessageFieldsTest method GetAllMessageFieldsForIndicesForNonexistingIndexShouldReturnEmptySet.
@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void GetAllMessageFieldsForIndicesForNonexistingIndexShouldReturnEmptySet() throws Exception {
final String[] indexNames = new String[] { "graylog_0" };
final IndicesExistsResponse response = client.admin().indices().exists(new IndicesExistsRequest("graylog_0")).get();
assertThat(response.isExists()).isFalse();
final Map<String, Set<String>> result = indices.getAllMessageFieldsForIndices(indexNames);
assertThat(result).isNotNull().isEmpty();
}
use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project beam by apache.
the class ElasticSearchIOTestUtils method deleteIndex.
/** Deletes the given index synchronously. */
static void deleteIndex(String index, Client client) throws Exception {
IndicesAdminClient indices = client.admin().indices();
IndicesExistsResponse indicesExistsResponse = indices.exists(new IndicesExistsRequest(index)).get();
if (indicesExistsResponse.isExists()) {
indices.prepareClose(index).get();
indices.delete(Requests.deleteIndexRequest(index)).get();
}
}
use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project syncope by apache.
the class ElasticsearchReindex method doExecute.
@Override
protected String doExecute(final boolean dryRun) throws JobExecutionException {
if (!dryRun) {
try {
LOG.debug("Start rebuild index {}", AuthContextUtils.getDomain().toLowerCase());
IndicesExistsResponse existsIndexResponse = client.admin().indices().exists(new IndicesExistsRequest(AuthContextUtils.getDomain().toLowerCase())).get();
if (existsIndexResponse.isExists()) {
DeleteIndexResponse deleteIndexResponse = client.admin().indices().delete(new DeleteIndexRequest(AuthContextUtils.getDomain().toLowerCase())).get();
LOG.debug("Successfully removed {}: {}", AuthContextUtils.getDomain().toLowerCase(), deleteIndexResponse);
}
XContentBuilder settings = XContentFactory.jsonBuilder().startObject().startObject("analysis").startObject("analyzer").startObject("string_lowercase").field("type", "custom").field("tokenizer", "standard").field("filter").startArray().value("lowercase").endArray().endObject().endObject().endObject().endObject();
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startArray("dynamic_templates").startObject().startObject("strings").field("match_mapping_type", "string").startObject("mapping").field("type", "keyword").field("analyzer", "string_lowercase").endObject().endObject().endObject().endArray().endObject();
CreateIndexResponse createIndexResponse = client.admin().indices().create(new CreateIndexRequest(AuthContextUtils.getDomain().toLowerCase()).settings(settings).mapping(AnyTypeKind.USER.name(), mapping).mapping(AnyTypeKind.GROUP.name(), mapping).mapping(AnyTypeKind.ANY_OBJECT.name(), mapping)).get();
LOG.debug("Successfully created {}: {}", AuthContextUtils.getDomain().toLowerCase(), createIndexResponse);
LOG.debug("Indexing users...");
for (int page = 1; page <= (userDAO.count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
for (User user : userDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
IndexResponse response = client.prepareIndex(AuthContextUtils.getDomain().toLowerCase(), AnyTypeKind.USER.name(), user.getKey()).setSource(elasticsearchUtils.builder(user)).get();
LOG.debug("Index successfully created for {}: {}", user, response);
}
}
LOG.debug("Indexing groups...");
for (int page = 1; page <= (groupDAO.count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
for (Group group : groupDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
IndexResponse response = client.prepareIndex(AuthContextUtils.getDomain().toLowerCase(), AnyTypeKind.GROUP.name(), group.getKey()).setSource(elasticsearchUtils.builder(group)).get();
LOG.debug("Index successfully created for {}: {}", group, response);
}
}
LOG.debug("Indexing any objects...");
for (int page = 1; page <= (anyObjectDAO.count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
for (AnyObject anyObject : anyObjectDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
IndexResponse response = client.prepareIndex(AuthContextUtils.getDomain().toLowerCase(), AnyTypeKind.ANY_OBJECT.name(), anyObject.getKey()).setSource(elasticsearchUtils.builder(anyObject)).get();
LOG.debug("Index successfully created for {}: {}", anyObject, response);
}
}
LOG.debug("Rebuild index {} successfully completed", AuthContextUtils.getDomain().toLowerCase());
} catch (Exception e) {
throw new JobExecutionException("While rebuilding index " + AuthContextUtils.getDomain().toLowerCase(), e);
}
}
return "SUCCESS";
}
use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project ecs-dashboard by carone1.
the class ElasticBillingDAO method initBillingNamespaceIndex.
// =======================
// Private methods
// =======================
// ===========================
// Billing namespace methods
// ===========================
private void initBillingNamespaceIndex(Date collectionTime) {
String collectionDayString = DATA_DATE_FORMAT.format(collectionTime);
billingNamespaceIndexDayName = BILLING_NAMESPACE_INDEX_NAME + "-" + collectionDayString;
if (elasticClient.admin().indices().exists(new IndicesExistsRequest(billingNamespaceIndexDayName)).actionGet().isExists()) {
// Index already exists need to truncate it and recreate it
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(billingNamespaceIndexDayName);
ActionFuture<DeleteIndexResponse> futureResult = elasticClient.admin().indices().delete(deleteIndexRequest);
// Wait until deletion is done
while (!futureResult.isDone()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
elasticClient.admin().indices().create(new CreateIndexRequest(billingNamespaceIndexDayName)).actionGet();
try {
PutMappingResponse putMappingResponse = elasticClient.admin().indices().preparePutMapping(billingNamespaceIndexDayName).setType(BILLING_NAMESPACE_INDEX_TYPE).setSource(XContentFactory.jsonBuilder().prettyPrint().startObject().startObject(BILLING_NAMESPACE_INDEX_TYPE).startObject("properties").startObject(NamespaceBillingInfo.TOTAL_SIZE_TAG).field("type", "long").endObject().startObject(NamespaceBillingInfo.TOTAL_SIZE_UNIT_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceBillingInfo.TOTAL_OBJECTS_TAG).field("type", "long").endObject().startObject(NamespaceBillingInfo.NAMESPACE_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceBillingInfo.NAMESPACE_TAG + ANALYZED_TAG).field("type", "string").field("index", ANALYZED_INDEX).endObject().startObject(COLLECTION_TIME).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().endObject().startArray("dynamic_templates").startObject().startObject("notanalyzed").field("match", "*").field("match_mapping_type", "string").startObject("mapping").field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().endObject().endObject().endArray().endObject().endObject()).execute().actionGet();
if (putMappingResponse.isAcknowledged()) {
LOGGER.info("Index Created: " + billingNamespaceIndexDayName);
} else {
LOGGER.error("Index {" + billingNamespaceIndexDayName + "} did not exist. " + "While attempting to create the index in ElasticSearch " + "Templates we were unable to get an acknowledgement.", billingNamespaceIndexDayName);
LOGGER.error("Error Message: {}", putMappingResponse.toString());
throw new RuntimeException("Unable to create index " + billingNamespaceIndexDayName);
}
} catch (IOException e) {
throw new RuntimeException("Unable to create index " + billingNamespaceIndexDayName + " " + e.getMessage());
}
}
use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project ecs-dashboard by carone1.
the class ElasticBucketOwnerDAO method initBucketOwnerIndex.
private void initBucketOwnerIndex(Date collectionTime) {
String collectionDayString = DATA_DATE_FORMAT.format(collectionTime);
bucketownerIndexDayName = BUCKET_OWNER_INDEX_NAME + "-" + collectionDayString;
if (elasticClient.admin().indices().exists(new IndicesExistsRequest(bucketownerIndexDayName)).actionGet().isExists()) {
// Index already exists need to truncate it and recreate it
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(bucketownerIndexDayName);
ActionFuture<DeleteIndexResponse> futureResult = elasticClient.admin().indices().delete(deleteIndexRequest);
// Wait until deletion is done
while (!futureResult.isDone()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
elasticClient.admin().indices().create(new CreateIndexRequest(bucketownerIndexDayName)).actionGet();
try {
PutMappingResponse putMappingResponse = elasticClient.admin().indices().preparePutMapping(bucketownerIndexDayName).setType(BUCKET_OWNER_INDEX_TYPE).setSource(XContentFactory.jsonBuilder().prettyPrint().startObject().startObject(BUCKET_OWNER_INDEX_TYPE).startObject("properties").startObject(BucketOwner.VDC_ID).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(BucketOwner.BUCKET_KEY).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(COLLECTION_TIME).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().endObject().startArray("dynamic_templates").startObject().startObject("notanalyzed").field("match", "*").field("match_mapping_type", "string").startObject("mapping").field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().endObject().endObject().endArray().endObject().endObject()).execute().actionGet();
if (putMappingResponse.isAcknowledged()) {
LOGGER.info("Index Created: " + bucketownerIndexDayName);
} else {
LOGGER.error("Index {" + bucketownerIndexDayName + "} did not exist. " + "While attempting to create the index in ElasticSearch " + "Templates we were unable to get an acknowledgement.", bucketownerIndexDayName);
LOGGER.error("Error Message: {}", putMappingResponse.toString());
throw new RuntimeException("Unable to create index " + bucketownerIndexDayName);
}
} catch (IOException e) {
throw new RuntimeException("Unable to create index " + bucketownerIndexDayName + " " + e.getMessage());
}
}
Aggregations