use of org.elasticsearch.action.admin.indices.alias.exists.AliasesExistResponse in project elasticsearch by elastic.
the class IndexAliasesIT method testIndicesGetAliases.
public void testIndicesGetAliases() throws Exception {
logger.info("--> creating indices [foobar, test, test123, foobarbaz, bazbar]");
createIndex("foobar");
createIndex("test");
createIndex("test123");
createIndex("foobarbaz");
createIndex("bazbar");
assertAcked(client().admin().indices().preparePutMapping("foobar", "test", "test123", "foobarbaz", "bazbar").setType("type").setSource("field", "type=text"));
ensureGreen();
logger.info("--> creating aliases [alias1, alias2]");
assertAcked(admin().indices().prepareAliases().addAlias("foobar", "alias1").addAlias("foobar", "alias2"));
logger.info("--> getting alias1");
GetAliasesResponse getResponse = admin().indices().prepareGetAliases("alias1").get();
assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(1));
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(1));
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("alias1"));
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
AliasesExistResponse existsResponse = admin().indices().prepareAliasesExist("alias1").get();
assertThat(existsResponse.exists(), equalTo(true));
logger.info("--> getting all aliases that start with alias*");
getResponse = admin().indices().prepareGetAliases("alias*").get();
assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(1));
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(2));
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("alias1"));
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(1), notNullValue());
assertThat(getResponse.getAliases().get("foobar").get(1).alias(), equalTo("alias2"));
assertThat(getResponse.getAliases().get("foobar").get(1).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(1).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(1).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("alias*").get();
assertThat(existsResponse.exists(), equalTo(true));
logger.info("--> creating aliases [bar, baz, foo]");
assertAcked(admin().indices().prepareAliases().addAlias("bazbar", "bar").addAlias("bazbar", "bac", termQuery("field", "value")).addAlias("foobar", "foo"));
assertAcked(admin().indices().prepareAliases().addAliasAction(AliasActions.add().index("foobar").alias("bac").routing("bla")));
logger.info("--> getting bar and baz for index bazbar");
getResponse = admin().indices().prepareGetAliases("bar", "bac").addIndices("bazbar").get();
assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(1));
assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2));
assertThat(getResponse.getAliases().get("bazbar").get(0), notNullValue());
assertThat(getResponse.getAliases().get("bazbar").get(0).alias(), equalTo("bac"));
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("term"));
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("field"));
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("value"));
assertThat(getResponse.getAliases().get("bazbar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(0).getSearchRouting(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1), notNullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).alias(), equalTo("bar"));
assertThat(getResponse.getAliases().get("bazbar").get(1).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("bar", "bac").addIndices("bazbar").get();
assertThat(existsResponse.exists(), equalTo(true));
logger.info("--> getting *b* for index baz*");
getResponse = admin().indices().prepareGetAliases("*b*").addIndices("baz*").get();
assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(1));
assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2));
assertThat(getResponse.getAliases().get("bazbar").get(0), notNullValue());
assertThat(getResponse.getAliases().get("bazbar").get(0).alias(), equalTo("bac"));
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("term"));
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("field"));
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("value"));
assertThat(getResponse.getAliases().get("bazbar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(0).getSearchRouting(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1), notNullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).alias(), equalTo("bar"));
assertThat(getResponse.getAliases().get("bazbar").get(1).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("*b*").addIndices("baz*").get();
assertThat(existsResponse.exists(), equalTo(true));
logger.info("--> getting *b* for index *bar");
getResponse = admin().indices().prepareGetAliases("b*").addIndices("*bar").get();
assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(2));
assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2));
assertThat(getResponse.getAliases().get("bazbar").get(0), notNullValue());
assertThat(getResponse.getAliases().get("bazbar").get(0).alias(), equalTo("bac"));
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("term"));
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("field"));
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("value"));
assertThat(getResponse.getAliases().get("bazbar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(0).getSearchRouting(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1), notNullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).alias(), equalTo("bar"));
assertThat(getResponse.getAliases().get("bazbar").get(1).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("bac"));
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), equalTo("bla"));
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), equalTo("bla"));
existsResponse = admin().indices().prepareAliasesExist("b*").addIndices("*bar").get();
assertThat(existsResponse.exists(), equalTo(true));
logger.info("--> getting f* for index *bar");
getResponse = admin().indices().prepareGetAliases("f*").addIndices("*bar").get();
assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(1));
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("foo"));
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("f*").addIndices("*bar").get();
assertThat(existsResponse.exists(), equalTo(true));
// alias at work
logger.info("--> getting f* for index *bac");
getResponse = admin().indices().prepareGetAliases("foo").addIndices("*bac").get();
assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(1));
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(1));
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("foo"));
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("foo").addIndices("*bac").get();
assertThat(existsResponse.exists(), equalTo(true));
logger.info("--> getting foo for index foobar");
getResponse = admin().indices().prepareGetAliases("foo").addIndices("foobar").get();
assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(1));
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("foo"));
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("foo").addIndices("foobar").get();
assertThat(existsResponse.exists(), equalTo(true));
// alias at work again
logger.info("--> getting * for index *bac");
getResponse = admin().indices().prepareGetAliases("*").addIndices("*bac").get();
assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(2));
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(4));
assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2));
existsResponse = admin().indices().prepareAliasesExist("*").addIndices("*bac").get();
assertThat(existsResponse.exists(), equalTo(true));
assertAcked(admin().indices().prepareAliases().removeAlias("foobar", "foo"));
getResponse = admin().indices().prepareGetAliases("foo").addIndices("foobar").get();
assertThat(getResponse.getAliases().isEmpty(), equalTo(true));
existsResponse = admin().indices().prepareAliasesExist("foo").addIndices("foobar").get();
assertThat(existsResponse.exists(), equalTo(false));
}
use of org.elasticsearch.action.admin.indices.alias.exists.AliasesExistResponse in project crate by crate.
the class PartitionedTableIntegrationTest method testDropPartitionedTable.
@Test
// no drop table rowcount
@UseJdbc(0)
public void testDropPartitionedTable() throws Exception {
execute("create table quotes (" + " id integer, " + " quote string, " + " date timestamp" + ") partitioned by (date) with (number_of_replicas=0)");
ensureYellow();
execute("insert into quotes (id, quote, date) values(?, ?, ?), (?, ?, ?)", new Object[] { 1, "Don't panic", 1395874800000L, 2, "Time is an illusion. Lunchtime doubly so", 1395961200000L });
ensureYellow();
refresh();
execute("drop table quotes");
assertEquals(1L, response.rowCount());
GetIndexTemplatesResponse getIndexTemplatesResponse = client().admin().indices().prepareGetTemplates(PartitionName.templateName(null, "quotes")).execute().get();
assertThat(getIndexTemplatesResponse.getIndexTemplates().size(), is(0));
assertThat(internalCluster().clusterService().state().metaData().indices().size(), is(0));
AliasesExistResponse aliasesExistResponse = client().admin().indices().prepareAliasesExist("quotes").execute().get();
assertFalse(aliasesExistResponse.exists());
}
use of org.elasticsearch.action.admin.indices.alias.exists.AliasesExistResponse in project elasticsearch by elastic.
the class IndexAliasesIT method testDeleteAliases.
public void testDeleteAliases() throws Exception {
logger.info("--> creating index [test1] and [test2]");
assertAcked(prepareCreate("test1").addMapping("type", "name", "type=text"));
assertAcked(prepareCreate("test2").addMapping("type", "name", "type=text"));
ensureGreen();
logger.info("--> adding filtering aliases to index [test1]");
assertAcked(admin().indices().prepareAliases().addAlias("test1", "aliasToTest1").addAlias("test1", "aliasToTests").addAlias("test1", "foos", termQuery("name", "foo")).addAlias("test1", "bars", termQuery("name", "bar")).addAlias("test1", "tests", termQuery("name", "test")));
logger.info("--> adding filtering aliases to index [test2]");
assertAcked(admin().indices().prepareAliases().addAlias("test2", "aliasToTest2").addAlias("test2", "aliasToTests").addAlias("test2", "foos", termQuery("name", "foo")).addAlias("test2", "tests", termQuery("name", "test")));
String[] indices = { "test1", "test2" };
String[] aliases = { "aliasToTest1", "foos", "bars", "tests", "aliasToTest2", "aliasToTests" };
admin().indices().prepareAliases().removeAlias(indices, aliases).get();
AliasesExistResponse response = admin().indices().prepareAliasesExist(aliases).get();
assertThat(response.exists(), equalTo(false));
}
Aggregations