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;
}
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;
}
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;
}
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;
}
Aggregations