use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project fess by codelibs.
the class FessEsClient method addMapping.
public void addMapping(final String index, final String docType, final String indexName) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final GetMappingsResponse getMappingsResponse = client.admin().indices().prepareGetMappings(indexName).execute().actionGet(fessConfig.getIndexIndicesTimeout());
final ImmutableOpenMap<String, MappingMetaData> indexMappings = getMappingsResponse.mappings().get(indexName);
if (indexMappings == null || !indexMappings.containsKey(docType)) {
String source = null;
final String mappingFile = indexConfigPath + "/" + index + "/" + docType + ".json";
try {
source = FileUtil.readUTF8(mappingFile);
} catch (final Exception e) {
logger.warn(mappingFile + " is not found.", e);
}
try {
final PutMappingResponse putMappingResponse = client.admin().indices().preparePutMapping(indexName).setType(docType).setSource(source, XContentFactory.xContentType(source)).execute().actionGet(fessConfig.getIndexIndicesTimeout());
if (putMappingResponse.isAcknowledged()) {
logger.info("Created " + indexName + "/" + docType + " mapping.");
} else {
logger.warn("Failed to create " + indexName + "/" + docType + " mapping.");
}
final String dataPath = indexConfigPath + "/" + index + "/" + docType + ".bulk";
if (ResourceUtil.isExist(dataPath)) {
insertBulkData(fessConfig, index, docType, dataPath);
}
} catch (final Exception e) {
logger.warn("Failed to create " + indexName + "/" + docType + " mapping.", e);
}
} else if (logger.isDebugEnabled()) {
logger.debug(indexName + "/" + docType + " mapping exists.");
}
}
use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse 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.mapping.put.PutMappingResponse 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());
}
}
use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project ecs-dashboard by carone1.
the class ElasticNamespaceDetailDAO method initNamespaceDetailIndex.
private void initNamespaceDetailIndex(Date collectionTime) {
String collectionDayString = DATA_DATE_FORMAT.format(collectionTime);
namespacedetailIndexDayName = NAMESPACE_DETAIL_INDEX_NAME + "-" + collectionDayString;
if (elasticClient.admin().indices().exists(new IndicesExistsRequest(namespacedetailIndexDayName)).actionGet().isExists()) {
// Index already exists need to truncate it and recreate it
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(namespacedetailIndexDayName);
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(namespacedetailIndexDayName)).actionGet();
try {
PutMappingResponse putMappingResponse = elasticClient.admin().indices().preparePutMapping(namespacedetailIndexDayName).setType(DETAIL_NAMESPACE_INDEX_TYPE).setSource(XContentFactory.jsonBuilder().prettyPrint().startObject().startObject(DETAIL_NAMESPACE_INDEX_TYPE).startObject("properties").startObject(NamespaceDetail.ID).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceDetail.LINK).field("type", "string").endObject().startObject(NamespaceDetail.NAME).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceDetail.NAME + ANALYZED_TAG).field("type", "string").field("index", ANALYZED_INDEX).endObject().startObject(NamespaceDetail.DEFAULT_DATA_SERVCIES_VPOOL).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceDetail.ALLOWED_VPOOLS_LIST).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceDetail.DISALLOWED_VPOOLS_LIST).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceDetail.NAMESPACE_ADMINS).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceDetail.IS_ENCRYPTION_ENABLED).field("type", "boolean").endObject().startObject(NamespaceDetail.DEFAULT_BUCKET_BLOCK_SIZE).field("type", "long").endObject().startObject(NamespaceDetail.USER_MAPPING).field("type", "string").endObject().startObject(NamespaceDetail.IS_STALE_ALLOWED).field("type", "boolean").endObject().startObject(NamespaceDetail.IS_COMPLIANCE_ENABLED).field("type", "boolean").endObject().startObject(NamespaceDetail.EXTERNAL_GROUP_ADMINS).field("type", "string").endObject().startObject(NamespaceDetail.GLOBAL).field("type", "boolean").endObject().startObject(NamespaceDetail.INACTIVE).field("type", "boolean").endObject().startObject(NamespaceDetail.REMOTE).field("type", "boolean").endObject().startObject(NamespaceDetail.INTERNAL).field("type", "boolean").endObject().startObject(NamespaceDetail.VDC).field("type", "string").endObject().startObject(NamespaceDetail.CREATION_TIME).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").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: " + namespacedetailIndexDayName);
} else {
LOGGER.error("Index {" + namespacedetailIndexDayName + "} did not exist. " + "While attempting to create the index in ElasticSearch " + "Templates we were unable to get an acknowledgement.", namespacedetailIndexDayName);
LOGGER.error("Error Message: {}", putMappingResponse.toString());
throw new RuntimeException("Unable to create index " + namespacedetailIndexDayName);
}
} catch (IOException e) {
throw new RuntimeException("Unable to create index " + namespacedetailIndexDayName + " " + e.getMessage());
}
}
use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project ecs-dashboard by carone1.
the class ElasticNamespaceQuotaDAO method initNamespaceQuotaIndex.
/**
* @param collectionTime
*/
private void initNamespaceQuotaIndex(Date collectionTime) {
String collectionDayString = DATA_DATE_FORMAT.format(collectionTime);
namespacequotaIndexDayName = NAMESPACE_QUOTA_INDEX_NAME + "-" + collectionDayString;
if (elasticClient.admin().indices().exists(new IndicesExistsRequest(namespacequotaIndexDayName)).actionGet().isExists()) {
// Index already exists need to truncate it and recreate it
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(namespacequotaIndexDayName);
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(namespacequotaIndexDayName)).actionGet();
try {
PutMappingResponse putMappingResponse = elasticClient.admin().indices().preparePutMapping(namespacequotaIndexDayName).setType(QUOTA_NAMESPACE_INDEX_TYPE).setSource(XContentFactory.jsonBuilder().prettyPrint().startObject().startObject(QUOTA_NAMESPACE_INDEX_TYPE).startObject("properties").startObject(NamespaceQuota.BLOCK_SIZE).field("type", "long").endObject().startObject(NamespaceQuota.NOTIFICATION_SIZE).field("type", "long").endObject().startObject(NamespaceQuota.NAMESPACE).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceQuota.NAMESPACE + 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: " + namespacequotaIndexDayName);
} else {
LOGGER.error("Index {" + namespacequotaIndexDayName + "} did not exist. " + "While attempting to create the index in ElasticSearch " + "Templates we were unable to get an acknowledgement.", namespacequotaIndexDayName);
LOGGER.error("Error Message: {}", putMappingResponse.toString());
throw new RuntimeException("Unable to create index " + namespacequotaIndexDayName);
}
} catch (IOException e) {
throw new RuntimeException("Unable to create index " + namespacequotaIndexDayName + " " + e.getMessage());
}
}
Aggregations