IndicesAdminClient indexAdmin = nodeClient.admin().indices();
CreateIndexRequestBuilder siteIdxRequest = indexAdmin.prepareCreate(site.getIdentifier());
logger.debug("Trying to create site index for '{}'", site.getIdentifier());
CreateIndexResponse siteidxResponse = siteIdxRequest.execute().actionGet();
if (!siteidxResponse.acknowledged()) {
throw new ContentRepositoryException("Unable to create site index for '" + site.getIdentifier() + "'");
}
} catch (IndexAlreadyExistsException e) {
logger.info("Detected existing index '{}'", site.getIdentifier());
}
// Store the correct mapping
// TODO: Use resource serializers
for (String type : new String[] {
"version",
"page",
"file",
"image",
"movie" }) {
PutMappingRequest siteMappingRequest = new PutMappingRequest(site.getIdentifier());
siteMappingRequest.source(loadMapping(type));
siteMappingRequest.type(type);
PutMappingResponse siteMappingResponse = nodeClient.admin().indices().putMapping(siteMappingRequest).actionGet();
if (!siteMappingResponse.acknowledged()) {
throw new ContentRepositoryException("Unable to install '" + type + "' mapping for index '" + site.getIdentifier() + "'");
}
}
// See if the index version exists and check if it matches. The request will
// fail if there is no version index