use of org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse in project fess by codelibs.
the class UpgradeUtil method addMapping.
public static boolean addMapping(final IndicesAdminClient indicesClient, final String index, final String type, final String indexResourcePath) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final GetMappingsResponse getMappingsResponse = indicesClient.prepareGetMappings(index).execute().actionGet(fessConfig.getIndexIndicesTimeout());
final ImmutableOpenMap<String, MappingMetadata> indexMappings = getMappingsResponse.mappings().get(index);
if (indexMappings == null || !indexMappings.containsKey(type)) {
String source = null;
final String mappingFile = indexResourcePath + "/" + type + ".json";
try {
source = FileUtil.readUTF8(mappingFile);
} catch (final Exception e) {
logger.warn("{} is not found.", mappingFile, e);
}
try {
final AcknowledgedResponse putMappingResponse = indicesClient.preparePutMapping(index).setSource(source, XContentType.JSON).execute().actionGet(fessConfig.getIndexIndicesTimeout());
if (putMappingResponse.isAcknowledged()) {
logger.info("Created {}/{} mapping.", index, type);
return true;
}
logger.warn("Failed to create {}/{} mapping.", index, type);
} catch (final Exception e) {
logger.warn("Failed to create {}/{} mapping.", index, type, e);
}
}
return false;
}
Aggregations