Search in sources :

Example 1 with FieldMappingMetadata

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;
}
Also used : FieldMappingMetadata(org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) GetFieldMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse) ResourceNotFoundRuntimeException(org.codelibs.core.exception.ResourceNotFoundRuntimeException)

Aggregations

ResourceNotFoundRuntimeException (org.codelibs.core.exception.ResourceNotFoundRuntimeException)1 GetFieldMappingsResponse (org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse)1 FieldMappingMetadata (org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata)1 AcknowledgedResponse (org.opensearch.action.support.master.AcknowledgedResponse)1