use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse 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.");
}
}
Aggregations