use of org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse in project elasticsearch by elastic.
the class SimpleIndexTemplateIT method testIndexTemplateWithAliasesSource.
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"));
}
use of org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse in project elasticsearch by elastic.
the class SimpleIndexTemplateIT method testIndexTemplateWithAliasesInSource.
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"));
}
use of org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse in project elasticsearch by elastic.
the class SimpleIndexTemplateIT method testMultipleAliasesPrecedence.
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"));
}
}
}
use of org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse in project elasticsearch by elastic.
the class SimpleIndexTemplateIT method testIndexTemplateWithAliases.
public void testIndexTemplateWithAliases() throws Exception {
client().admin().indices().preparePutTemplate("template_with_aliases").setPatterns(Collections.singletonList("te*")).addMapping("type1", "{\"type1\" : {\"properties\" : {\"value\" : {\"type\" : \"text\"}}}}", XContentType.JSON).addAlias(new Alias("simple_alias")).addAlias(new Alias("templated_alias-{index}")).addAlias(new Alias("filtered_alias").filter("{\"type\":{\"value\":\"type2\"}}")).addAlias(new Alias("complex_filtered_alias").filter(QueryBuilders.termsQuery("_type", "typeX", "typeY", "typeZ"))).get();
assertAcked(prepareCreate("test_index").addMapping("type1").addMapping("type2").addMapping("typeX").addMapping("typeY").addMapping("typeZ"));
ensureGreen();
client().prepareIndex("test_index", "type1", "1").setSource("field", "A value").get();
client().prepareIndex("test_index", "type2", "2").setSource("field", "B value").get();
client().prepareIndex("test_index", "typeX", "3").setSource("field", "C value").get();
client().prepareIndex("test_index", "typeY", "4").setSource("field", "D value").get();
client().prepareIndex("test_index", "typeZ", "5").setSource("field", "E value").get();
GetAliasesResponse getAliasesResponse = client().admin().indices().prepareGetAliases().setIndices("test_index").get();
assertThat(getAliasesResponse.getAliases().size(), equalTo(1));
assertThat(getAliasesResponse.getAliases().get("test_index").size(), equalTo(4));
refresh();
SearchResponse searchResponse = client().prepareSearch("test_index").get();
assertHitCount(searchResponse, 5L);
searchResponse = client().prepareSearch("simple_alias").get();
assertHitCount(searchResponse, 5L);
searchResponse = client().prepareSearch("templated_alias-test_index").get();
assertHitCount(searchResponse, 5L);
searchResponse = client().prepareSearch("filtered_alias").get();
assertHitCount(searchResponse, 1L);
assertThat(searchResponse.getHits().getAt(0).getType(), equalTo("type2"));
// Search the complex filter alias
searchResponse = client().prepareSearch("complex_filtered_alias").get();
assertHitCount(searchResponse, 3L);
Set<String> types = new HashSet<>();
for (SearchHit searchHit : searchResponse.getHits().getHits()) {
types.add(searchHit.getType());
}
assertThat(types.size(), equalTo(3));
assertThat(types, containsInAnyOrder("typeX", "typeY", "typeZ"));
}
use of org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse in project elasticsearch by elastic.
the class RestAliasAction method doCatRequest.
@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);
}
});
}
Aggregations