org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse Java Examples
The following examples show how to use
org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestAliasAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
private Table buildTable(RestRequest request, GetAliasesResponse response) { Table table = getTableWithHeader(request); for (ObjectObjectCursor<String, List<AliasMetaData>> cursor : response.getAliases()) { String indexName = cursor.key; for (AliasMetaData aliasMetaData : cursor.value) { table.startRow(); table.addCell(aliasMetaData.alias()); table.addCell(indexName); table.addCell(aliasMetaData.filteringRequired() ? "*" : "-"); String indexRouting = Strings.hasLength(aliasMetaData.indexRouting()) ? aliasMetaData.indexRouting() : "-"; table.addCell(indexRouting); String searchRouting = Strings.hasLength(aliasMetaData.searchRouting()) ? aliasMetaData.searchRouting() : "-"; table.addCell(searchRouting); table.endRow(); } } return table; }
Example #2
Source File: CrudDemo.java From javabase with Apache License 2.0 | 6 votes |
/** * 索引 别名 就像一个快捷方式或软连接,可以指向一个或多个索引,也可以给任何需要索引名的 API 使用。别名带给我们极大的灵活性, * 比如 我们线上使用一个索引名为index_a的结构,里面有一个类型现在不满足要求,现在需要修改,因为elasticsearch不支持直接修改类型,所以我们必须要重新建立一个新的索引 * 然后将久索引的数据拷贝过去。 但是如果让新的索引起作用,我们需要要修改引用代码,因为索引名称更换了,但是如果我们一开始创建索引的时候就给索引增加一个别名 * 使用的时候都是使用index_alis 无论软连接的指向是什么索引,对外暴露的始终都是index_alis * @param indicesAdminClient */ private static void createAliasIndex(IndicesAdminClient indicesAdminClient) { // 1 创建索引 elsdb_alis_v1。 // 2 将别名 elsdb_alis 指向 elsdb_alis_v1 // 3 然后,我们决定修改索引elsdb_alis_v1中一个字段的映射。当然我们不能修改现存的映射,索引我们需要重新索引数据。首先,我们创建有新的映射的索引 elsdb_alis_v2。 // 4 然后我们从将数据从 elsdb_alis_v1 迁移到 elsdb_alis_v2,下面的过程在【重新索引】中描述过了。一旦我们认为数据已经被正确的索引了,我们就将别名指向新的索引。 //创建索引 if (checkExistsIndex(indicesAdminClient, INDEX_ALIAS_NAME_VERSION_ONE)) { deleteIndex(indicesAdminClient, INDEX_ALIAS_NAME_VERSION_ONE); } indicesAdminClient.prepareCreate(INDEX_ALIAS_NAME_VERSION_ONE).setSettings().execute().actionGet(); //添加alias 所有别名 indicesAdminClient.prepareAliases().addAlias(INDEX_ALIAS_NAME_VERSION_ONE,INDEX_ALIAS_NAME_ALIS).execute().actionGet(); GetAliasesResponse getAliasesResponse = indicesAdminClient.getAliases(new GetAliasesRequest().indices(INDEX_ALIAS_NAME_ALIS)).actionGet(); //log.info("getAliasesResponse index setting:{}", getAliasesResponse.getAliases()); indicesAdminClient.prepareAliases().removeAlias(INDEX_ALIAS_NAME_VERSION_ONE,INDEX_ALIAS_NAME_ALIS).addAlias(INDEX_ALIAS_NAME_VERSION_TWO,INDEX_ALIAS_NAME_ALIS); }
Example #3
Source File: BaseClient.java From elasticsearch-helper with Apache License 2.0 | 6 votes |
public String resolveMostRecentIndex(String alias) { if (client() == null) { return alias; } if (alias == null) { return null; } GetAliasesRequestBuilder getAliasesRequestBuilder = new GetAliasesRequestBuilder(client(), GetAliasesAction.INSTANCE); GetAliasesResponse getAliasesResponse = getAliasesRequestBuilder.setAliases(alias).execute().actionGet(); Pattern pattern = Pattern.compile("^(.*?)(\\d+)$"); Set<String> indices = new TreeSet<>(Collections.reverseOrder()); for (ObjectCursor<String> indexName : getAliasesResponse.getAliases().keys()) { Matcher m = pattern.matcher(indexName.value); if (m.matches()) { if (alias.equals(m.group(1))) { indices.add(indexName.value); } } } return indices.isEmpty() ? alias : indices.iterator().next(); }
Example #4
Source File: RestGetAliasesAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { final String[] aliases = request.paramAsStringArrayOrEmptyIfAll("name"); final String[] indices = Strings.splitStringByCommaToArray(request.param("index")); final GetAliasesRequest getAliasesRequest = new GetAliasesRequest(aliases); getAliasesRequest.indices(indices); getAliasesRequest.indicesOptions(IndicesOptions.fromRequest(request, getAliasesRequest.indicesOptions())); getAliasesRequest.local(request.paramAsBoolean("local", getAliasesRequest.local())); client.admin().indices().getAliases(getAliasesRequest, new RestBuilderListener<GetAliasesResponse>(channel) { @Override public RestResponse buildResponse(GetAliasesResponse response, XContentBuilder builder) throws Exception { // empty body, if indices were specified but no aliases were if (indices.length > 0 && response.getAliases().isEmpty()) { return new BytesRestResponse(OK, builder.startObject().endObject()); } else if (response.getAliases().isEmpty()) { String message = String.format(Locale.ROOT, "alias [%s] missing", toNamesString(getAliasesRequest.aliases())); builder.startObject() .field("error", message) .field("status", RestStatus.NOT_FOUND.getStatus()) .endObject(); return new BytesRestResponse(RestStatus.NOT_FOUND, builder); } builder.startObject(); for (ObjectObjectCursor<String, List<AliasMetaData>> entry : response.getAliases()) { builder.startObject(entry.key, XContentBuilder.FieldCaseConversion.NONE); builder.startObject(Fields.ALIASES); for (AliasMetaData alias : entry.value) { AliasMetaData.Builder.toXContent(alias, builder, ToXContent.EMPTY_PARAMS); } builder.endObject(); builder.endObject(); } builder.endObject(); return new BytesRestResponse(OK, builder); } }); }
Example #5
Source File: RestAliasAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void doRequest(final RestRequest request, final RestChannel channel, final Client client) { final GetAliasesRequest getAliasesRequest = request.hasParam("alias") ? new GetAliasesRequest(request.param("alias")) : new GetAliasesRequest(); getAliasesRequest.local(request.paramAsBoolean("local", getAliasesRequest.local())); client.admin().indices().getAliases(getAliasesRequest, new RestResponseListener<GetAliasesResponse>(channel) { @Override public RestResponse buildResponse(GetAliasesResponse response) throws Exception { Table tab = buildTable(request, response); return RestTable.buildResponse(tab, channel); } }); }
Example #6
Source File: BaseClient.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
public String resolveAlias(String alias) { if (client() == null) { return alias; } GetAliasesRequestBuilder getAliasesRequestBuilder = new GetAliasesRequestBuilder(client(), GetAliasesAction.INSTANCE); GetAliasesResponse getAliasesResponse = getAliasesRequestBuilder.setAliases(alias).execute().actionGet(); if (!getAliasesResponse.getAliases().isEmpty()) { return getAliasesResponse.getAliases().keys().iterator().next().value; } return alias; }
Example #7
Source File: BaseClient.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
private Map<String,String> getFilters(GetAliasesResponse getAliasesResponse) { Map<String,String> result = new HashMap<>(); for (ObjectObjectCursor<String, List<AliasMetaData>> object : getAliasesResponse.getAliases()) { List<AliasMetaData> aliasMetaDataList = object.value; for (AliasMetaData aliasMetaData : aliasMetaDataList) { if (aliasMetaData.filteringRequired()) { result.put(aliasMetaData.alias(), new String(aliasMetaData.getFilter().uncompressed())); } else { result.put(aliasMetaData.alias(), null); } } } return result; }
Example #8
Source File: AbstractClient.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public ActionFuture<GetAliasesResponse> getAliases(GetAliasesRequest request) { return execute(GetAliasesAction.INSTANCE, request); }
Example #9
Source File: AbstractClient.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public void getAliases(GetAliasesRequest request, ActionListener<GetAliasesResponse> listener) { execute(GetAliasesAction.INSTANCE, request, listener); }
Example #10
Source File: ElasticsearchClusterRunner.java From elasticsearch-cluster-runner with Apache License 2.0 | 4 votes |
public GetAliasesResponse getAlias(final String alias) { return getAlias(alias, builder -> builder); }
Example #11
Source File: ElasticsearchClusterRunner.java From elasticsearch-cluster-runner with Apache License 2.0 | 4 votes |
public GetAliasesResponse getAlias(final String alias, final BuilderCallback<GetAliasesRequestBuilder> builder) { return builder.apply(client().admin().indices().prepareGetAliases(alias)).execute().actionGet(); }
Example #12
Source File: IndicesAdminClient.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * Get specific index aliases that exists in particular indices and / or by name. * * @param request The result future */ ActionFuture<GetAliasesResponse> getAliases(GetAliasesRequest request);
Example #13
Source File: IndicesAdminClient.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * Get specific index aliases that exists in particular indices and / or by name. * * @param request The index aliases request * @param listener A listener to be notified with a result */ void getAliases(GetAliasesRequest request, ActionListener<GetAliasesResponse> listener);