当前位置: 首页>>代码示例>>Java>>正文


Java GetAliasesRequest类代码示例

本文整理汇总了Java中org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest的典型用法代码示例。如果您正苦于以下问题:Java GetAliasesRequest类的具体用法?Java GetAliasesRequest怎么用?Java GetAliasesRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GetAliasesRequest类属于org.elasticsearch.action.admin.indices.alias.get包,在下文中一共展示了GetAliasesRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createAliasIndex

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
/**
     * 索引 别名 就像一个快捷方式或软连接,可以指向一个或多个索引,也可以给任何需要索引名的 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);
    }
 
开发者ID:ggj2010,项目名称:javabase,代码行数:29,代码来源:CrudDemo.java

示例2: should_create_alias

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
@Test
public void should_create_alias() throws Exception {
    String index = "index_without_alias";
    createIndex(index);
    ensureGreen(index);

    IndicesAliasesRequest request = new IndicesAliasesRequest();
    request.addAlias("the_alias", index);
    IndicesAliasesResponse response = httpClient.admin().indices().aliases(request).get();

    Assertions.assertThat(response.isAcknowledged()).isTrue();

    GetAliasesResponse finalState = transportClient.admin().indices().getAliases(new GetAliasesRequest()).actionGet();
    Assertions.assertThat(finalState.getAliases().get(index)).hasSize(1);
    Assertions.assertThat(finalState.getAliases().get(index).get(0).alias()).isEqualTo("the_alias");
    Assertions.assertThat(finalState.getAliases().get(index).get(0).filter()).isNull();
    Assertions.assertThat(finalState.getAliases().get(index).get(0).getIndexRouting()).isNull();
    Assertions.assertThat(finalState.getAliases().get(index).get(0).getSearchRouting()).isNull();
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:20,代码来源:IndicesAliasesActionHandlerTest.java

示例3: should_delete_alias

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
@Test
public void should_delete_alias() throws Exception {
    String index = "index_without_alias";
    createIndex(index);
    ensureGreen(index);

    transportClient.admin().indices().aliases(new IndicesAliasesRequest().addAlias("the_alias", index)).actionGet();
    GetAliasesResponse actualAlias = transportClient.admin().indices().getAliases(new GetAliasesRequest().indices(index)).actionGet();
    Assertions.assertThat(actualAlias.getAliases().containsKey(index)).isTrue();
    Assertions.assertThat(actualAlias.getAliases().get(index)).hasSize(1);
    Assertions.assertThat(actualAlias.getAliases().get(index).get(0).alias()).isEqualTo("the_alias");

    IndicesAliasesRequest request = new IndicesAliasesRequest();
    request.removeAlias(index, "the_alias");
    IndicesAliasesResponse response = httpClient.admin().indices().aliases(request).get();

    Assertions.assertThat(response.isAcknowledged()).isTrue();

    GetAliasesResponse finalState = transportClient.admin().indices().getAliases(new GetAliasesRequest()).actionGet();
    Assertions.assertThat(finalState.getAliases()).hasSize(0);
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:22,代码来源:IndicesAliasesActionHandlerTest.java

示例4: should_create_alias_with_filter

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
@Test
public void should_create_alias_with_filter() throws Exception {
    String index = "index_without_alias";
    createIndex(index);
    ensureGreen(index);

    // add a mapping so I can add a filter, else it will fail due to strict resolution of fields
    createSimpleDoc(index, THE_TYPE, THE_ID);
    ensureSearchable(index);

    IndicesAliasesRequest request = new IndicesAliasesRequest();
    TermFilterBuilder filter = termFilter("the_string_field", "some_value");

    request.addAlias("the_alias", filter, index);
    IndicesAliasesResponse response = httpClient.admin().indices().aliases(request).get();

    Assertions.assertThat(response.isAcknowledged()).isTrue();

    GetAliasesResponse finalState = transportClient.admin().indices().getAliases(new GetAliasesRequest()).actionGet();
    Assertions.assertThat(finalState.getAliases().get(index)).hasSize(1);
    Assertions.assertThat(finalState.getAliases().get(index).get(0).alias()).isEqualTo("the_alias");

    String requestFilter = request.getAliasActions().get(0).aliasAction().filter();
    CompressedString actualFilter = finalState.getAliases().get(index).get(0).filter();
    Assertions.assertThat(actualFilter.string()).isEqualTo(requestFilter);
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:27,代码来源:IndicesAliasesActionHandlerTest.java

示例5: should_create_alias_with_routing

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
@Test
public void should_create_alias_with_routing() throws Exception {
    String index = "index_without_alias";
    createIndex(index);
    ensureGreen(index);

    IndicesAliasesRequest request = new IndicesAliasesRequest();

    request.addAliasAction(new AliasAction(AliasAction.Type.ADD).alias("the_alias").index(index).searchRouting("the_search_routing").indexRouting("the_index_routing"));
    IndicesAliasesResponse response = httpClient.admin().indices().aliases(request).get();

    Assertions.assertThat(response.isAcknowledged()).isTrue();

    GetAliasesResponse finalState = transportClient.admin().indices().getAliases(new GetAliasesRequest()).actionGet();
    Assertions.assertThat(finalState.getAliases().get(index)).hasSize(1);
    Assertions.assertThat(finalState.getAliases().get(index).get(0).alias()).isEqualTo("the_alias");
    Assertions.assertThat(finalState.getAliases().get(index).get(0).searchRouting()).isEqualTo("the_search_routing");
    Assertions.assertThat(finalState.getAliases().get(index).get(0).indexRouting()).isEqualTo("the_index_routing");
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:20,代码来源:IndicesAliasesActionHandlerTest.java

示例6: doCatRequest

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final GetAliasesRequest getAliasesRequest = request.hasParam("alias") ?
            new GetAliasesRequest(request.param("alias")) :
            new GetAliasesRequest();
    getAliasesRequest.local(request.paramAsBoolean("local", getAliasesRequest.local()));

    return channel -> 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);
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:RestAliasAction.java

示例7: handleRequest

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
@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);
        }
    });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:40,代码来源:RestGetAliasesAction.java

示例8: doRequest

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
@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);
        }
    });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:16,代码来源:RestAliasAction.java

示例9: doService

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
private void doService() {
    List<IndexType> indexs = IndexType.getAllIndex();
    IndicesAdminClient adminClient = ESClient.getClient().admin().indices();
    for (IndexType indexType : indexs) {
        String indexname = indexType.getIndexName().toLowerCase();
        String lastIndexName = null;
        try {
            lastIndexName = updateLogger.getLastIndexName(indexType);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (adminClient.prepareExists(indexType.index_type_1()).execute().actionGet()
                .isExists()
                && adminClient
                        .aliasesExist(
                                new GetAliasesRequest().indices(indexType.index_type_1())
                                        .aliases(indexname)).actionGet().isExists()) {
            if (adminClient.prepareExists(indexType.index_type_2()).execute().actionGet()
                    .isExists()
                    && adminClient
                            .aliasesExist(
                                    new GetAliasesRequest().indices(indexType.index_type_2())
                                            .aliases(indexname)).actionGet().isExists()) {
                log.error("indexname:{},{} alias:{}", indexType.index_type_1(),
                        indexType.index_type_2(), indexname);
                if (lastIndexName != null && indexType.index_type_1().equals(lastIndexName)) {
                    adminClient.delete(new DeleteIndexRequest(indexType.index_type_2()));// 删除索引
                } else {
                    adminClient.delete(new DeleteIndexRequest(indexType.index_type_1()));// 删除索引
                }
            }
        }
    }
}
 
开发者ID:hailin0,项目名称:es-service-parent,代码行数:35,代码来源:AliasMonitorService.java

示例10: execute

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
public void execute(GetAliasesRequest request, final ActionListener<GetAliasesResponse> listener) {
    logger.debug("get aliases request {}", request);
    try {
        String indices = HttpRequestUtils.indicesOrAll(request);
        String aliases = Strings.arrayToCommaDelimitedString(request.aliases());
        if (!aliases.isEmpty()) {
            aliases = "/_alias/" + aliases;
        }
        RequestUriBuilder uriBuilder = new RequestUriBuilder(indices).addEndpoint(aliases);
        uriBuilder.addIndicesOptions(request);

        uriBuilder.addQueryParameter("master_timeout", request.masterNodeTimeout().toString());
        uriBuilder.addQueryParameter("local", request.local());

        indicesAdminClient.getHttpClient().submit(HttpClientRequest.createGet(uriBuilder.toString()))
                .flatMap(ErrorHandler.AS_FUNC)
                .flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<GetAliasesResponse>>() {
                    @Override
                    public Observable<GetAliasesResponse> call(final HttpClientResponse<ByteBuf> response) {
                        return response.getContent().flatMap(new Func1<ByteBuf, Observable<GetAliasesResponse>>() {
                            @Override
                            public Observable<GetAliasesResponse> call(ByteBuf byteBuf) {
                                return GetAliasesResponse.parse(byteBuf);
                            }
                        });
                    }
                })
                .single()
                .subscribe(new ListenerCompleterObserver<>(listener));
    } catch (Exception e) {
        listener.onFailure(e);
    }
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:34,代码来源:GetAliasesActionHandler.java

示例11: testSwitchAlias

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
@Test
public void testSwitchAlias() {
    createIndex(INDEX_2);
    client().admin().indices().aliases(Requests.indexAliasesRequest().addAlias(ALIAS, INDEX)).actionGet();

    operations.switchAlias(ALIAS, INDEX, INDEX_2).actionGet();

    GetAliasesResponse response = client().admin().indices().getAliases(new GetAliasesRequest(ALIAS)).actionGet();
    Assertions.assertThat(response.getAliases().size()).isEqualTo(1);
    ObjectObjectCursor<String, List<AliasMetaData>> cursor = response.getAliases().iterator().next();
    Assertions.assertThat(cursor.key).isEqualTo(INDEX_2);
    Assertions.assertThat(cursor.value.size()).isEqualTo(1);
    Assertions.assertThat(cursor.value.iterator().next().alias()).isEqualTo(ALIAS);
}
 
开发者ID:obourgain,项目名称:elasticsearch-batch,代码行数:15,代码来源:ElasticsearchBatchOperationsAsyncTest.java

示例12: getIndexesFromEs

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
private String[] getIndexesFromEs(final String aliasName){
    final AdminClient adminClient = this.provider.getClient().admin();
         //remove write alias, can only have one
    ImmutableOpenMap<String, List<AliasMetaData>> aliasMap =
        adminClient.indices().getAliases( new GetAliasesRequest( aliasName ) ).actionGet().getAliases();
    return aliasMap.keys().toArray( String.class );
}
 
开发者ID:apache,项目名称:usergrid,代码行数:8,代码来源:EsIndexCacheImpl.java

示例13: getAliases

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
@Override
public ActionFuture<GetAliasesResponse> getAliases(GetAliasesRequest request) {
    return execute(GetAliasesAction.INSTANCE, request);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:AbstractClient.java

示例14: aliasesExist

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
@Override
public void aliasesExist(GetAliasesRequest request, ActionListener<AliasesExistResponse> listener) {
    execute(AliasesExistAction.INSTANCE, request, listener);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:AbstractClient.java

示例15: prepareRequest

import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] aliases = request.paramAsStringArrayOrEmptyIfAll("name");
    final GetAliasesRequest getAliasesRequest = new GetAliasesRequest(aliases);
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    getAliasesRequest.indices(indices);
    getAliasesRequest.indicesOptions(IndicesOptions.fromRequest(request, getAliasesRequest.indicesOptions()));
    getAliasesRequest.local(request.paramAsBoolean("local", getAliasesRequest.local()));

    return channel -> client.admin().indices().getAliases(getAliasesRequest, new RestBuilderListener<GetAliasesResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetAliasesResponse response, XContentBuilder builder) throws Exception {
            if (response.getAliases().isEmpty()) {
                // empty body if indices were specified but no matching aliases exist
                if (indices.length > 0) {
                    return new BytesRestResponse(OK, builder.startObject().endObject());
                } else {
                    final String message = String.format(Locale.ROOT, "alias [%s] missing", toNamesString(getAliasesRequest.aliases()));
                    builder.startObject();
                    {
                        builder.field("error", message);
                        builder.field("status", RestStatus.NOT_FOUND.getStatus());
                    }
                    builder.endObject();
                    return new BytesRestResponse(RestStatus.NOT_FOUND, builder);
                }
            } else {
                builder.startObject();
                {
                    for (final ObjectObjectCursor<String, List<AliasMetaData>> entry : response.getAliases()) {
                        builder.startObject(entry.key);
                        {
                            builder.startObject("aliases");
                            {
                                for (final AliasMetaData alias : entry.value) {
                                    AliasMetaData.Builder.toXContent(alias, builder, ToXContent.EMPTY_PARAMS);
                                }
                            }
                            builder.endObject();
                        }
                        builder.endObject();
                    }
                }
                builder.endObject();
                return new BytesRestResponse(OK, builder);
            }
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:50,代码来源:RestGetAliasesAction.java


注:本文中的org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。