use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project ecs-dashboard by carone1.
the class ElasticS3ObjectDAO method initS3ObjectIndex.
// =======================
// Private methods
// =======================
/**
* Init Object index
*/
private void initS3ObjectIndex(Date collectionTime) {
String collectionDayString = DATA_DATE_FORMAT.format(collectionTime);
s3ObjectIndexDayName = S3_OBJECT_INDEX_NAME + "-" + collectionDayString;
if (elasticClient.admin().indices().exists(new IndicesExistsRequest(s3ObjectIndexDayName)).actionGet().isExists()) {
// Index already exists need to truncate it and recreate it
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(s3ObjectIndexDayName);
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(s3ObjectIndexDayName)).actionGet();
try {
PutMappingResponse putMappingResponse = elasticClient.admin().indices().preparePutMapping(s3ObjectIndexDayName).setType(S3_OBJECT_INDEX_TYPE).setSource(XContentFactory.jsonBuilder().prettyPrint().startObject().startObject(S3_OBJECT_INDEX_TYPE).startObject("properties").startObject(LAST_MODIFIED_TAG).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().startObject(SIZE_TAG).field("type", "string").field("type", "long").endObject().startObject(KEY_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(KEY_TAG + ANALYZED_TAG).field("type", "string").field("index", ANALYZED_INDEX).endObject().startObject(ETAG_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NAMESPACE_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(BUCKET_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(OWNER_ID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(OWNER_NAME_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(COLLECTION_TIME).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().startObject(CUSTOM_GID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(CUSTOM_UID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(CUSTOM_MODIFIED_TIME_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).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: " + s3ObjectIndexDayName);
} else {
LOGGER.error("Index {} did not exist. " + "While attempting to create the index from stored ElasticSearch " + "Templates we were unable to get an acknowledgement.", s3ObjectIndexDayName);
LOGGER.error("Error Message: {}", putMappingResponse.toString());
throw new RuntimeException("Unable to create index " + s3ObjectIndexDayName);
}
} catch (IOException e) {
throw new RuntimeException("Unable to create index " + s3ObjectIndexDayName + " " + e.getMessage());
}
}
use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project ecs-dashboard by carone1.
the class ElasticS3ObjectDAO method initS3ObjectVersionIndex.
/**
* Init Object version index
*/
private void initS3ObjectVersionIndex(Date collectionTime) {
String collectionDayString = DATA_DATE_FORMAT.format(collectionTime);
s3ObjectVersionIndexDayName = S3_OBJECT_VERSION_INDEX_NAME + "-" + collectionDayString;
if (elasticClient.admin().indices().exists(new IndicesExistsRequest(s3ObjectVersionIndexDayName)).actionGet().isExists()) {
// Index already exists need to truncate it and recreate it
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(s3ObjectVersionIndexDayName);
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(s3ObjectVersionIndexDayName)).actionGet();
try {
PutMappingResponse putMappingResponse = elasticClient.admin().indices().preparePutMapping(s3ObjectVersionIndexDayName).setType(S3_OBJECT_VERSION_INDEX_TYPE).setSource(XContentFactory.jsonBuilder().prettyPrint().startObject().startObject(S3_OBJECT_VERSION_INDEX_TYPE).startObject("properties").startObject(LAST_MODIFIED_TAG).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().startObject(SIZE_TAG).field("type", "string").field("type", "long").endObject().startObject(KEY_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(KEY_TAG + ANALYZED_TAG).field("type", "string").field("index", ANALYZED_INDEX).endObject().startObject(ETAG_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NAMESPACE_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(BUCKET_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VERSION_ID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(IS_LATEST_TAG).field("type", "boolean").field("index", NOT_ANALYZED_INDEX).endObject().startObject(OWNER_ID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(OWNER_NAME_TAG).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: " + s3ObjectVersionIndexDayName);
} else {
LOGGER.error("Index {} did not exist. " + "While attempting to create the index from stored ElasticSearch " + "Templates we were unable to get an acknowledgement.", s3ObjectVersionIndexDayName);
LOGGER.error("Error Message: {}", putMappingResponse.toString());
throw new RuntimeException("Unable to create index " + s3ObjectVersionIndexDayName);
}
} catch (IOException e) {
throw new RuntimeException("Unable to create index " + s3ObjectVersionIndexDayName + " " + e.getMessage());
}
}
use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project play2-elasticsearch by cleverage.
the class IndexService method createMapping.
/**
* Create Mapping ( for example mapping type : nested, geo_point )
* see http://www.elasticsearch.org/guide/reference/mapping/
* <p/>
* {
* "tweet" : {
* "properties" : {
* "message" : {"type" : "string", "store" : "yes"}
* }
* }
* }
*
* @param indexName
* @param indexType
* @param indexMapping
*/
public static PutMappingResponse createMapping(String indexName, String indexType, String indexMapping) {
Logger.debug("ElasticSearch : creating mapping [" + indexName + "/" + indexType + "] : " + indexMapping);
PutMappingResponse response = IndexClient.client.admin().indices().preparePutMapping(indexName).setType(indexType).setSource(indexMapping).execute().actionGet();
return response;
}
use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project uavstack by uavorg.
the class ESClient method setIndexTypeMapping.
/**
* setIndexTypeMapping require Index Creation first
*
* @param index
* @param type
* @param properties
* @return
* @throws IOException
*/
public boolean setIndexTypeMapping(String index, String type, Map<String, Map<String, Object>> properties) throws IOException {
PutMappingRequest pmp = Requests.putMappingRequest(index).type(type).source(createMapping(type, properties));
PutMappingResponse resp = client.admin().indices().putMapping(pmp).actionGet();
return resp.isAcknowledged();
}
use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project vertigo by KleeGroup.
the class AbstractESSearchServicesPlugin method updateTypeMapping.
/**
* Update template definition of this type.
* @param indexDefinition Index concerné
*/
private void updateTypeMapping(final SearchIndexDefinition indexDefinition, final boolean sortableNormalizer) {
Assertion.checkNotNull(indexDefinition);
// -----
try (final XContentBuilder typeMapping = XContentFactory.jsonBuilder()) {
typeMapping.startObject().startObject("properties").startObject(ESDocumentCodec.FULL_RESULT).field("type", "binary").endObject();
/* 3 : Les champs du dto index */
final Set<DtField> copyFromFields = indexDefinition.getIndexCopyFromFields();
final DtDefinition indexDtDefinition = indexDefinition.getIndexDtDefinition();
for (final DtField dtField : indexDtDefinition.getFields()) {
final IndexType indexType = IndexType.readIndexType(dtField.getDomain());
typeMapping.startObject(dtField.getName());
appendIndexTypeMapping(typeMapping, indexType);
if (copyFromFields.contains(dtField)) {
appendIndexCopyToMapping(indexDefinition, typeMapping, dtField);
}
if (indexType.isIndexSubKeyword()) {
typeMapping.startObject("fields");
typeMapping.startObject("keyword");
typeMapping.field("type", "keyword");
if (sortableNormalizer) {
typeMapping.field("normalizer", "sortable");
}
typeMapping.endObject();
typeMapping.endObject();
}
if (indexType.isIndexFieldData()) {
typeMapping.field("fielddata", true);
}
typeMapping.endObject();
}
// end properties
typeMapping.endObject().endObject();
final PutMappingResponse putMappingResponse = esClient.admin().indices().preparePutMapping(obtainIndexName(indexDefinition)).setType(indexDefinition.getName().toLowerCase(Locale.ROOT)).setSource(typeMapping).get();
putMappingResponse.isAcknowledged();
} catch (final IOException e) {
throw WrappedException.wrap(e, "Serveur ElasticSearch indisponible");
}
}
Aggregations