本文整理汇总了Java中org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse类的典型用法代码示例。如果您正苦于以下问题:Java GetAliasesResponse类的具体用法?Java GetAliasesResponse怎么用?Java GetAliasesResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GetAliasesResponse类属于org.elasticsearch.action.admin.indices.alias.get包,在下文中一共展示了GetAliasesResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildTable
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的package包/类
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;
}
示例2: checkAliases
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的package包/类
private void checkAliases() {
GetAliasesResponse getAliasesResponse = admin().indices().prepareGetAliases("alias1").get();
assertThat(getAliasesResponse.getAliases().get("test").size(), equalTo(1));
AliasMetaData aliasMetaData = getAliasesResponse.getAliases().get("test").get(0);
assertThat(aliasMetaData.alias(), equalTo("alias1"));
assertThat(aliasMetaData.filter(), nullValue());
assertThat(aliasMetaData.indexRouting(), nullValue());
assertThat(aliasMetaData.searchRouting(), nullValue());
getAliasesResponse = admin().indices().prepareGetAliases("alias2").get();
assertThat(getAliasesResponse.getAliases().get("test").size(), equalTo(1));
aliasMetaData = getAliasesResponse.getAliases().get("test").get(0);
assertThat(aliasMetaData.alias(), equalTo("alias2"));
assertThat(aliasMetaData.filter(), notNullValue());
assertThat(aliasMetaData.indexRouting(), nullValue());
assertThat(aliasMetaData.searchRouting(), nullValue());
getAliasesResponse = admin().indices().prepareGetAliases("alias3").get();
assertThat(getAliasesResponse.getAliases().get("test").size(), equalTo(1));
aliasMetaData = getAliasesResponse.getAliases().get("test").get(0);
assertThat(aliasMetaData.alias(), equalTo("alias3"));
assertThat(aliasMetaData.filter(), nullValue());
assertThat(aliasMetaData.indexRouting(), equalTo("index"));
assertThat(aliasMetaData.searchRouting(), equalTo("search"));
}
示例3: createAliasIndex
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的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);
}
示例4: should_create_alias
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的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();
}
示例5: should_delete_alias
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的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);
}
示例6: should_create_alias_with_filter
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的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);
}
示例7: should_create_alias_with_routing
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的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");
}
示例8: resolveMostRecentIndex
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的package包/类
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();
}
示例9: testPutIndexAlias
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的package包/类
@Test
public void testPutIndexAlias(){
//Create index
final CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(indexName);
@SuppressWarnings ("unused")
CreateIndexResponse createIndexResponse = createIndexRequestBuilder.execute().actionGet();
//Put the alias
String alias = "test_alias";
IndexAdminHelper helper = new IndexAdminHelperImpl (client);
IndicesAliasesResponse response = helper.putIndexAlias (indexName, alias);
assertTrue(response.isAcknowledged ());
GetAliasesRequestBuilder aliasesRequestBuilder = client.admin ().indices ().prepareGetAliases ();
GetAliasesResponse getAliasesResponse = aliasesRequestBuilder.execute ().actionGet ();
List<AliasMetaData> aliases = getAliasesResponse.getAliases ().get (indexName);
if(log.isDebugEnabled ())
for(AliasMetaData aliasMetaData : aliases)
log.debug(String.format("***** Internal Index Name: %s", aliasMetaData.alias ()));
assertEquals (1, aliases.size ());
assertEquals (alias, aliases.get (0).alias ());
}
示例10: doCatRequest
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的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);
}
});
}
示例11: testIndexTemplateWithAliasesInSource
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的package包/类
public void testIndexTemplateWithAliasesInSource() {
client().admin().indices().preparePutTemplate("template_1")
.setSource(new BytesArray("{\n" +
" \"template\" : \"*\",\n" +
" \"aliases\" : {\n" +
" \"my_alias\" : {\n" +
" \"filter\" : {\n" +
" \"type\" : {\n" +
" \"value\" : \"type2\"\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}"), XContentType.JSON).get();
assertAcked(prepareCreate("test_index").addMapping("type1").addMapping("type2"));
ensureGreen();
GetAliasesResponse getAliasesResponse = client().admin().indices().prepareGetAliases().setIndices("test_index").get();
assertThat(getAliasesResponse.getAliases().size(), equalTo(1));
assertThat(getAliasesResponse.getAliases().get("test_index").size(), equalTo(1));
client().prepareIndex("test_index", "type1", "1").setSource("field", "value1").get();
client().prepareIndex("test_index", "type2", "2").setSource("field", "value2").get();
refresh();
SearchResponse searchResponse = client().prepareSearch("test_index").get();
assertHitCount(searchResponse, 2L);
searchResponse = client().prepareSearch("my_alias").get();
assertHitCount(searchResponse, 1L);
assertThat(searchResponse.getHits().getAt(0).getType(), equalTo("type2"));
}
示例12: testIndexTemplateWithAliasesSource
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的package包/类
public void testIndexTemplateWithAliasesSource() {
client().admin().indices().preparePutTemplate("template_1")
.setPatterns(Collections.singletonList("te*"))
.setAliases(
" {\n" +
" \"alias1\" : {},\n" +
" \"alias2\" : {\n" +
" \"filter\" : {\n" +
" \"type\" : {\n" +
" \"value\" : \"type2\"\n" +
" }\n" +
" }\n" +
" },\n" +
" \"alias3\" : { \"routing\" : \"1\" }" +
" }\n").get();
assertAcked(prepareCreate("test_index").addMapping("type1").addMapping("type2"));
ensureGreen();
GetAliasesResponse getAliasesResponse = client().admin().indices().prepareGetAliases().setIndices("test_index").get();
assertThat(getAliasesResponse.getAliases().size(), equalTo(1));
assertThat(getAliasesResponse.getAliases().get("test_index").size(), equalTo(3));
client().prepareIndex("test_index", "type1", "1").setSource("field", "value1").get();
client().prepareIndex("test_index", "type2", "2").setSource("field", "value2").get();
refresh();
SearchResponse searchResponse = client().prepareSearch("test_index").get();
assertHitCount(searchResponse, 2L);
searchResponse = client().prepareSearch("alias1").get();
assertHitCount(searchResponse, 2L);
searchResponse = client().prepareSearch("alias2").get();
assertHitCount(searchResponse, 1L);
assertThat(searchResponse.getHits().getAt(0).getType(), equalTo("type2"));
}
示例13: testMultipleAliasesPrecedence
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的package包/类
public void testMultipleAliasesPrecedence() throws Exception {
client().admin().indices().preparePutTemplate("template1")
.setPatterns(Collections.singletonList("*"))
.setOrder(0)
.addAlias(new Alias("alias1"))
.addAlias(new Alias("{index}-alias"))
.addAlias(new Alias("alias3").filter(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("test"))))
.addAlias(new Alias("alias4")).get();
client().admin().indices().preparePutTemplate("template2")
.setPatterns(Collections.singletonList("te*"))
.setOrder(1)
.addAlias(new Alias("alias1").routing("test"))
.addAlias(new Alias("alias3")).get();
assertAcked(prepareCreate("test").addAlias(new Alias("test-alias").searchRouting("test-routing")));
ensureGreen();
GetAliasesResponse getAliasesResponse = client().admin().indices().prepareGetAliases().addIndices("test").get();
assertThat(getAliasesResponse.getAliases().get("test").size(), equalTo(4));
for (AliasMetaData aliasMetaData : getAliasesResponse.getAliases().get("test")) {
assertThat(aliasMetaData.alias(), anyOf(equalTo("alias1"), equalTo("test-alias"), equalTo("alias3"), equalTo("alias4")));
if ("alias1".equals(aliasMetaData.alias())) {
assertThat(aliasMetaData.indexRouting(), equalTo("test"));
assertThat(aliasMetaData.searchRouting(), equalTo("test"));
} else if ("alias3".equals(aliasMetaData.alias())) {
assertThat(aliasMetaData.filter(), nullValue());
} else if ("test-alias".equals(aliasMetaData.alias())) {
assertThat(aliasMetaData.indexRouting(), nullValue());
assertThat(aliasMetaData.searchRouting(), equalTo("test-routing"));
}
}
}
示例14: testGetAllAliasesWorks
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的package包/类
public void testGetAllAliasesWorks() {
createIndex("index1");
createIndex("index2");
assertAcked(admin().indices().prepareAliases().addAlias("index1", "alias1").addAlias("index2", "alias2"));
GetAliasesResponse response = admin().indices().prepareGetAliases().get();
assertThat(response.getAliases(), hasKey("index1"));
assertThat(response.getAliases(), hasKey("index1"));
}
示例15: handleRequest
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; //导入依赖的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);
}
});
}