Search in sources :

Example 1 with GetMappingsResponse

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

Aggregations

ResourceNotFoundRuntimeException (org.codelibs.core.exception.ResourceNotFoundRuntimeException)1 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)1 FieldMappingMetadata (org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata)1 GetMappingsResponse (org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse)1 AcknowledgedResponse (org.opensearch.action.support.master.AcknowledgedResponse)1 MappingMetadata (org.opensearch.cluster.metadata.MappingMetadata)1