Search in sources :

Example 1 with AcknowledgedResponse

use of org.opensearch.action.support.master.AcknowledgedResponse in project fess by codelibs.

the class UpgradeUtil method createAlias.

public static boolean createAlias(final IndicesAdminClient indicesClient, final String indexConfigPath, final String indexName, final String aliasName) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final String aliasConfigPath = indexConfigPath + "/" + indexName + "/alias/" + aliasName + ".json";
    try {
        final File aliasConfigFile = org.codelibs.core.io.ResourceUtil.getResourceAsFile(aliasConfigPath);
        if (aliasConfigFile.exists()) {
            final String source = FileUtil.readUTF8(aliasConfigFile);
            final AcknowledgedResponse response = indicesClient.prepareAliases().addAlias(indexName, aliasName, source).execute().actionGet(fessConfig.getIndexIndicesTimeout());
            if (response.isAcknowledged()) {
                logger.info("Created {} alias for {}", aliasName, indexName);
                return true;
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to create {} alias for {}", aliasName, indexName);
            }
        }
    } catch (final ResourceNotFoundRuntimeException e) {
    // ignore
    } catch (final Exception e) {
        logger.warn("{} is not found.", aliasConfigPath, e);
    }
    return false;
}
Also used : AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) File(java.io.File) ResourceNotFoundRuntimeException(org.codelibs.core.exception.ResourceNotFoundRuntimeException) ResourceNotFoundRuntimeException(org.codelibs.core.exception.ResourceNotFoundRuntimeException)

Example 2 with AcknowledgedResponse

use of org.opensearch.action.support.master.AcknowledgedResponse 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)

Example 3 with AcknowledgedResponse

use of org.opensearch.action.support.master.AcknowledgedResponse 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)

Example 4 with AcknowledgedResponse

use of org.opensearch.action.support.master.AcknowledgedResponse in project fess by codelibs.

the class UpgradeUtil method putMapping.

public static boolean putMapping(final IndicesAdminClient indicesClient, final String index, final String type, final String source) {
    try {
        final PutMappingRequestBuilder builder = indicesClient.preparePutMapping(index).setSource(source, XContentType.JSON);
        final AcknowledgedResponse pmResponse = builder.execute().actionGet();
        if (pmResponse.isAcknowledged()) {
            return true;
        }
        logger.warn("Failed to update {} settings.", index);
    } catch (final Exception e) {
        logger.warn("Failed to update {} settings.", index, e);
    }
    return false;
}
Also used : PutMappingRequestBuilder(org.opensearch.action.admin.indices.mapping.put.PutMappingRequestBuilder) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) ResourceNotFoundRuntimeException(org.codelibs.core.exception.ResourceNotFoundRuntimeException)

Aggregations

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