本文整理汇总了Java中org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions类的典型用法代码示例。如果您正苦于以下问题:Java AliasActions类的具体用法?Java AliasActions怎么用?Java AliasActions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AliasActions类属于org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest包,在下文中一共展示了AliasActions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAliasSearchRoutingWithConcreteAndAliasedIndices_issue2682
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
public void testAliasSearchRoutingWithConcreteAndAliasedIndices_issue2682() throws Exception {
createIndex("index", "index_2");
ensureGreen();
assertAcked(admin().indices().prepareAliases()
.addAliasAction(AliasActions.add().index("index").alias("index_1").routing("1")));
logger.info("--> indexing on index_1 which is an alias for index with routing [1]");
client().prepareIndex("index_1", "type1", "1").setSource("field", "value1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
logger.info("--> indexing on index_2 which is a concrete index");
client().prepareIndex("index_2", "type2", "2").setSource("field", "value2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
logger.info("--> search all on index_* should find two");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch("index_*").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L));
}
}
示例2: testAliasSearchRoutingWithConcreteAndAliasedIndices_issue3268
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
public void testAliasSearchRoutingWithConcreteAndAliasedIndices_issue3268() throws Exception {
createIndex("index", "index_2");
ensureGreen();
assertAcked(admin().indices().prepareAliases()
.addAliasAction(AliasActions.add().index("index").alias("index_1").routing("1")));
logger.info("--> indexing on index_1 which is an alias for index with routing [1]");
client().prepareIndex("index_1", "type1", "1").setSource("field", "value1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
logger.info("--> indexing on index_2 which is a concrete index");
client().prepareIndex("index_2", "type2", "2").setSource("field", "value2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
SearchResponse searchResponse = client().prepareSearch("index_*").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(1).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
logger.info("--> search all on index_* should find two");
assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
//Let's make sure that, even though 2 docs are available, only one is returned according to the size we set in the request
//Therefore the reduce phase has taken place, which proves that the QUERY_AND_FETCH search type wasn't erroneously forced.
assertThat(searchResponse.getHits().getHits().length, equalTo(1));
}
示例3: testEmptyIndex
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
public void testEmptyIndex() {
Exception e = expectThrows(IllegalArgumentException.class,
() -> new AliasActions(randomFrom(AliasActions.Type.values())).index(null));
assertEquals("[index] can't be empty string", e.getMessage());
e = expectThrows(IllegalArgumentException.class,
() -> new AliasActions(randomFrom(AliasActions.Type.values())).index(""));
assertEquals("[index] can't be empty string", e.getMessage());
e = expectThrows(IllegalArgumentException.class,
() -> new AliasActions(randomFrom(AliasActions.Type.values())).indices((String[]) null));
assertEquals("[indices] can't be empty", e.getMessage());
e = expectThrows(IllegalArgumentException.class,
() -> new AliasActions(randomFrom(AliasActions.Type.values())).indices(new String[0]));
assertEquals("[indices] can't be empty", e.getMessage());
e = expectThrows(IllegalArgumentException.class,
() -> new AliasActions(randomFrom(AliasActions.Type.values())).indices("test", null));
assertEquals("[indices] can't contain empty string", e.getMessage());
e = expectThrows(IllegalArgumentException.class,
() -> new AliasActions(randomFrom(AliasActions.Type.values())).indices("test", ""));
assertEquals("[indices] can't contain empty string", e.getMessage());
}
示例4: testParseRemoveIndex
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
public void testParseRemoveIndex() throws IOException {
String[] indices = randomBoolean() ? new String[] {randomAsciiOfLength(5)} : generateRandomStringArray(10, 5, false, false);
XContentBuilder b = XContentBuilder.builder(randomFrom(XContentType.values()).xContent());
b.startObject(); {
b.startObject("remove_index"); {
if (indices.length > 1 || randomBoolean()) {
b.array("indices", indices);
} else {
b.field("index", indices[0]);
}
}
b.endObject();
}
b.endObject();
b = shuffleXContent(b);
try (XContentParser parser = createParser(b)) {
AliasActions action = AliasActions.PARSER.apply(parser, null);
assertEquals(AliasActions.Type.REMOVE_INDEX, action.actionType());
assertArrayEquals(indices, action.indices());
assertThat(action.aliases(), arrayWithSize(0));
}
}
示例5: testParseIndexAndIndicesThrowsError
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
public void testParseIndexAndIndicesThrowsError() throws IOException {
XContentBuilder b = XContentBuilder.builder(randomFrom(XContentType.values()).xContent());
b.startObject(); {
b.startObject(randomFrom("add", "remove")); {
b.field("index", randomAsciiOfLength(5));
b.array("indices", generateRandomStringArray(10, 5, false, false));
b.field("alias", randomAsciiOfLength(5));
}
b.endObject();
}
b.endObject();
try (XContentParser parser = createParser(b)) {
Exception e = expectThrows(ParsingException.class, () -> AliasActions.PARSER.apply(parser, null));
assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class));
assertEquals("Only one of [index] and [indices] is supported", e.getCause().getCause().getMessage());
}
}
示例6: testParseAliasAndAliasesThrowsError
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
public void testParseAliasAndAliasesThrowsError() throws IOException {
XContentBuilder b = XContentBuilder.builder(randomFrom(XContentType.values()).xContent());
b.startObject(); {
b.startObject(randomFrom("add", "remove")); {
b.field("index", randomAsciiOfLength(5));
b.field("alias", randomAsciiOfLength(5));
b.array("aliases", generateRandomStringArray(10, 5, false, false));
}
b.endObject();
}
b.endObject();
try (XContentParser parser = createParser(b)) {
Exception e = expectThrows(ParsingException.class, () -> AliasActions.PARSER.apply(parser, null));
assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class));
assertEquals("Only one of [alias] and [aliases] is supported", e.getCause().getCause().getMessage());
}
}
示例7: addIndexAlias
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
/**
* Adds a new alias to an existing index.
* @param indexName the index name
* @param aliasName the alias
* @param withAliasRouting enables alias routing for index with filtering by appid
* @return true if acknowledged
*/
public static boolean addIndexAlias(String indexName, String aliasName, boolean withAliasRouting) {
if (StringUtils.isBlank(aliasName) || !existsIndex(indexName)) {
return false;
}
try {
String alias = aliasName.trim();
String index = getIndexNameWithWildcard(indexName.trim());
AliasActions aliasBuilder;
if (withAliasRouting) {
aliasBuilder = AliasActions.add().index(index).alias(alias).
searchRouting(alias).indexRouting(alias).
filter(termQuery(Config._APPID, aliasName)); // DO NOT trim filter query!
} else {
aliasBuilder = AliasActions.add().index(index).alias(alias);
}
return getClient().admin().indices().prepareAliases().addAliasAction(aliasBuilder).
execute().actionGet().isAcknowledged();
} catch (Exception e) {
logger.error(null, e);
return false;
}
}
示例8: prepareRequest
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
final String[] aliases = Strings.splitStringByCommaToArray(request.param("name"));
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
indicesAliasesRequest.addAliasAction(AliasActions.remove().indices(indices).aliases(aliases));
indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));
return channel -> client.admin().indices().aliases(indicesAliasesRequest, new AcknowledgedRestListener<>(channel));
}
示例9: checkBlock
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
@Override
protected ClusterBlockException checkBlock(IndicesAliasesRequest request, ClusterState state) {
Set<String> indices = new HashSet<>();
for (AliasActions aliasAction : request.aliasActions()) {
for (String index : aliasAction.indices()) {
indices.add(index);
}
}
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indices.toArray(new String[indices.size()]));
}
示例10: testMultipleIndicesAllocation
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
public void testMultipleIndicesAllocation() throws Exception {
client().admin().indices().prepareCreate("test1").setSettings(Settings.builder()
.put("index.number_of_shards", "4").put("index.number_of_replicas", 1)).execute().actionGet();
client().admin().indices().prepareCreate("test2").setSettings(Settings.builder()
.put("index.number_of_shards", "4").put("index.number_of_replicas", 1)).execute().actionGet();
client().admin().indices().prepareAliases()
.addAliasAction(AliasActions.add().index("test1").alias("routing_alias").routing("ABC"))
.addAliasAction(AliasActions.add().index("test2").alias("routing_alias").routing("EFG"))
.get();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
ClusterSearchShardsResponse response = client().admin().cluster().prepareSearchShards("routing_alias").execute().actionGet();
assertThat(response.getGroups().length, equalTo(2));
assertThat(response.getGroups()[0].getShards().length, equalTo(2));
assertThat(response.getGroups()[1].getShards().length, equalTo(2));
boolean seenTest1 = false;
boolean seenTest2 = false;
for (ClusterSearchShardsGroup group : response.getGroups()) {
if (group.getShardId().getIndexName().equals("test1")) {
seenTest1 = true;
assertThat(group.getShards().length, equalTo(2));
} else if (group.getShardId().getIndexName().equals("test2")) {
seenTest2 = true;
assertThat(group.getShards().length, equalTo(2));
} else {
fail();
}
}
assertThat(seenTest1, equalTo(true));
assertThat(seenTest2, equalTo(true));
assertThat(response.getNodes().length, equalTo(2));
}
示例11: testEmptyAlias
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
public void testEmptyAlias() {
AliasActions.Type type = randomValueOtherThan(AliasActions.Type.REMOVE_INDEX, () -> randomFrom(AliasActions.Type.values()));
Exception e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).alias(null));
assertEquals("[alias] can't be empty string", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).alias(""));
assertEquals("[alias] can't be empty string", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).aliases((String[]) null));
assertEquals("[aliases] can't be empty", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).aliases(new String[0]));
assertEquals("[aliases] can't be empty", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).aliases("test", null));
assertEquals("[aliases] can't contain empty string", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).aliases("test", ""));
assertEquals("[aliases] can't contain empty string", e.getMessage());
}
示例12: testBadOptionsInNonIndex
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
public void testBadOptionsInNonIndex() {
AliasActions action = randomBoolean() ? AliasActions.remove() : AliasActions.removeIndex();
Exception e = expectThrows(IllegalArgumentException.class, () -> action.routing("test"));
assertEquals("[routing] is unsupported for [" + action.actionType() + "]", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> action.searchRouting("test"));
assertEquals("[search_routing] is unsupported for [" + action.actionType() + "]", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> action.indexRouting("test"));
assertEquals("[index_routing] is unsupported for [" + action.actionType() + "]", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> action.filter("test"));
assertEquals("[filter] is unsupported for [" + action.actionType() + "]", e.getMessage());
}
示例13: testParseAddDefaultRouting
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
public void testParseAddDefaultRouting() throws IOException {
String index = randomAsciiOfLength(5);
String alias = randomAsciiOfLength(5);
Object searchRouting = randomRouting();
Object indexRouting = randomRouting();
XContentBuilder b = XContentBuilder.builder(randomFrom(XContentType.values()).xContent());
b.startObject(); {
b.startObject("add"); {
b.field("index", index);
b.field("alias", alias);
if (randomBoolean()) {
b.field("routing", searchRouting);
b.field("index_routing", indexRouting);
} else {
b.field("search_routing", searchRouting);
b.field("routing", indexRouting);
}
}
b.endObject();
}
b.endObject();
b = shuffleXContent(b);
try (XContentParser parser = createParser(b)) {
AliasActions action = AliasActions.PARSER.apply(parser, null);
assertEquals(AliasActions.Type.ADD, action.actionType());
assertThat(action.indices(), arrayContaining(index));
assertThat(action.aliases(), arrayContaining(alias));
assertEquals(searchRouting.toString(), action.searchRouting());
assertEquals(indexRouting.toString(), action.indexRouting());
}
}
示例14: testParseRemove
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
public void testParseRemove() throws IOException {
String[] indices = generateRandomStringArray(10, 5, false, false);
String[] aliases = generateRandomStringArray(10, 5, false, false);
XContentBuilder b = XContentBuilder.builder(randomFrom(XContentType.values()).xContent());
b.startObject(); {
b.startObject("remove"); {
if (indices.length > 1 || randomBoolean()) {
b.array("indices", indices);
} else {
b.field("index", indices[0]);
}
if (aliases.length > 1 || randomBoolean()) {
b.array("aliases", aliases);
} else {
b.field("alias", aliases[0]);
}
}
b.endObject();
}
b.endObject();
b = shuffleXContent(b);
try (XContentParser parser = createParser(b)) {
AliasActions action = AliasActions.PARSER.apply(parser, null);
assertEquals(AliasActions.Type.REMOVE, action.actionType());
assertThat(action.indices(), equalTo(indices));
assertThat(action.aliases(), equalTo(aliases));
}
}
示例15: testRoundTrip
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; //导入依赖的package包/类
public void testRoundTrip() throws IOException {
AliasActions action = new AliasActions(randomFrom(AliasActions.Type.values()));
if (randomBoolean()) {
action.index(randomAsciiOfLength(5));
} else {
action.indices(generateRandomStringArray(5, 5, false, false));
}
if (action.actionType() != AliasActions.Type.REMOVE_INDEX) {
if (randomBoolean()) {
action.alias(randomAsciiOfLength(5));
} else {
action.aliases(generateRandomStringArray(5, 5, false, false));
}
}
if (action.actionType() == AliasActions.Type.ADD) {
if (randomBoolean()) {
action.filter(randomAsciiOfLength(10));
}
if (randomBoolean()) {
if (randomBoolean()) {
action.routing(randomAsciiOfLength(5));
} else {
action.searchRouting(randomAsciiOfLength(5));
action.indexRouting(randomAsciiOfLength(5));
}
}
}
try (BytesStreamOutput out = new BytesStreamOutput()) {
action.writeTo(out);
try (StreamInput in = out.bytes().streamInput()) {
AliasActions read = new AliasActions(in);
assertEquals(action, read);
}
}
}