use of org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata in project fess by codelibs.
the class UpgradeUtil method addFieldMapping.
public static boolean addFieldMapping(final IndicesAdminClient indicesClient, final String index, final String type, final String field, final String source) {
final GetFieldMappingsResponse gfmResponse = indicesClient.prepareGetFieldMappings(index).addTypes(type).setFields(field).execute().actionGet();
final FieldMappingMetadata fieldMappings = gfmResponse.fieldMappings(index, type, field);
if (fieldMappings == null || fieldMappings.isNull()) {
try {
final AcknowledgedResponse pmResponse = indicesClient.preparePutMapping(index).setSource(source, XContentType.JSON).execute().actionGet();
if (pmResponse.isAcknowledged()) {
return true;
}
logger.warn("Failed to add {} to {}/{}", field, index, type);
} catch (final Exception e) {
logger.warn("Failed to add {} to {}/{} ", field, index, type, e);
}
}
return false;
}
Aggregations