use of org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse in project fess by codelibs.
the class FessEsClient method createAlias.
protected void createAlias(final String index, final String createdIndexName) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
// alias
final String aliasConfigDirPath = indexConfigPath + "/" + index + "/alias";
try {
final File aliasConfigDir = ResourceUtil.getResourceAsFile(aliasConfigDirPath);
if (aliasConfigDir.isDirectory()) {
stream(aliasConfigDir.listFiles((dir, name) -> name.endsWith(".json"))).of(stream -> stream.forEach(f -> {
final String aliasName = f.getName().replaceFirst(".json$", "");
String source = FileUtil.readUTF8(f);
if (source.trim().equals("{}")) {
source = null;
}
final IndicesAliasesResponse response = client.admin().indices().prepareAliases().addAlias(createdIndexName, aliasName, source).execute().actionGet(fessConfig.getIndexIndicesTimeout());
if (response.isAcknowledged()) {
logger.info("Created " + aliasName + " alias for " + createdIndexName);
} else if (logger.isDebugEnabled()) {
logger.debug("Failed to create " + aliasName + " alias for " + createdIndexName);
}
}));
}
} catch (final ResourceNotFoundRuntimeException e) {
// ignore
} catch (final Exception e) {
logger.warn(aliasConfigDirPath + " is not found.", e);
}
}
use of org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse in project fess by codelibs.
the class FessEsClient method updateAlias.
public boolean updateAlias(final String newIndex) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
String updateAlias = fessConfig.getIndexDocumentUpdateIndex();
String searchAlias = fessConfig.getIndexDocumentSearchIndex();
final GetIndexResponse response1 = client.admin().indices().prepareGetIndex().addIndices(updateAlias).execute().actionGet(fessConfig.getIndexIndicesTimeout());
final String[] updateIndices = response1.indices();
final GetIndexResponse response2 = client.admin().indices().prepareGetIndex().addIndices(searchAlias).execute().actionGet(fessConfig.getIndexIndicesTimeout());
final String[] searchIndices = response2.indices();
IndicesAliasesRequestBuilder builder = client.admin().indices().prepareAliases().addAlias(newIndex, updateAlias).addAlias(newIndex, searchAlias);
for (String index : updateIndices) {
builder.removeAlias(index, updateAlias);
}
for (String index : searchIndices) {
builder.removeAlias(index, searchAlias);
}
IndicesAliasesResponse response = builder.execute().actionGet(fessConfig.getIndexIndicesTimeout());
return response.isAcknowledged();
}
Aggregations