本文整理汇总了Java中org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse类的典型用法代码示例。如果您正苦于以下问题:Java IndicesAliasesResponse类的具体用法?Java IndicesAliasesResponse怎么用?Java IndicesAliasesResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IndicesAliasesResponse类属于org.elasticsearch.action.admin.indices.alias包,在下文中一共展示了IndicesAliasesResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: alias
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的package包/类
/**
* Create an alias for a pattern
*
* @param aliases
* a map of patterns to alias
* @return true if the request was acknowledged
*/
public boolean alias(Map<String, String> aliases) {
boolean acknowledged = false;
if (aliases.isEmpty()) {
LOGGER.trace("The alias map is empty. Nothing to do");
return acknowledged;
}
IndicesAliasesRequestBuilder builder = this.client.admin().indices().prepareAliases();
addCommonHeaders(builder);
for (Map.Entry<String, String> entry : aliases.entrySet()) {
LOGGER.debug("Creating alias for {} as {}", entry.getKey(), entry.getValue());
builder.addAlias(entry.getKey(), entry.getValue());
}
IndicesAliasesResponse response = builder.get();
acknowledged = response.isAcknowledged();
LOGGER.debug("Aliases request acknowledged? {}", acknowledged);
return acknowledged;
}
示例2: testSimpleCloseOpenAlias
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的package包/类
public void testSimpleCloseOpenAlias() {
Client client = client();
createIndex("test1");
ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
assertThat(healthResponse.isTimedOut(), equalTo(false));
IndicesAliasesResponse aliasesResponse = client.admin().indices().prepareAliases().addAlias("test1", "test1-alias").execute().actionGet();
assertThat(aliasesResponse.isAcknowledged(), equalTo(true));
CloseIndexResponse closeIndexResponse = client.admin().indices().prepareClose("test1-alias").execute().actionGet();
assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
assertIndexIsClosed("test1");
OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test1-alias").execute().actionGet();
assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
assertIndexIsOpened("test1");
}
示例3: testCloseOpenAliasMultipleIndices
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的package包/类
public void testCloseOpenAliasMultipleIndices() {
Client client = client();
createIndex("test1", "test2");
ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
assertThat(healthResponse.isTimedOut(), equalTo(false));
IndicesAliasesResponse aliasesResponse1 = client.admin().indices().prepareAliases().addAlias("test1", "test-alias").execute().actionGet();
assertThat(aliasesResponse1.isAcknowledged(), equalTo(true));
IndicesAliasesResponse aliasesResponse2 = client.admin().indices().prepareAliases().addAlias("test2", "test-alias").execute().actionGet();
assertThat(aliasesResponse2.isAcknowledged(), equalTo(true));
CloseIndexResponse closeIndexResponse = client.admin().indices().prepareClose("test-alias").execute().actionGet();
assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
assertIndexIsClosed("test1", "test2");
OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test-alias").execute().actionGet();
assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
assertIndexIsOpened("test1", "test2");
}
示例4: testAddAlias
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的package包/类
@Test
public void testAddAlias() {
//Test data
final String indexName = "index";
final String aliasName = "alias";
final AdminClient adminClient = createMock(AdminClient.class);
final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
final IndicesAliasesRequestBuilder indicesAliasesRequestBuilder = createMock(IndicesAliasesRequestBuilder.class);
final IndicesAliasesResponse indicesAliasesResponse = createMock(IndicesAliasesResponse.class);
//Reset
resetAll();
//Expectations
expect(esClient.admin()).andReturn(adminClient);
expect(adminClient.indices()).andReturn(indicesAdminClient);
expect(indicesAdminClient.prepareAliases()).andReturn(indicesAliasesRequestBuilder);
expect(indicesAliasesRequestBuilder.addAlias(indexName, aliasName)).andReturn(indicesAliasesRequestBuilder);
expect(indicesAliasesRequestBuilder.get()).andReturn(indicesAliasesResponse);
//Replay
replayAll();
//Run test scenario
final boolean result = elasticsearchClientWrapper.addAlias(indexName, aliasName);
//Verify
verifyAll();
assertEquals(indicesAliasesResponse.isAcknowledged(), result);
}
示例5: testExistsByAliasTrue
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的package包/类
@Test
public void testExistsByAliasTrue () {
//create index
final CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(indexName);
createIndexRequestBuilder.execute().actionGet();
//create alias
String alias = "test_alias";
IndicesAliasesRequestBuilder builder = client.admin().indices ().prepareAliases ().addAlias (indexName, alias);
IndicesAliasesResponse response = builder.execute ().actionGet ();
assertTrue(response.isAcknowledged ());
//test exists
IndexAdminHelper helper = new IndexAdminHelperImpl (client);
assertTrue(helper.exists (alias));
}
示例6: testGetIndexAliases
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的package包/类
@Test
public void testGetIndexAliases(){
//Create index
final CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(indexName);
@SuppressWarnings ("unused")
CreateIndexResponse createIndexResponse = createIndexRequestBuilder.execute().actionGet();
//Put the alias
String alias = "test_alias";
IndicesAliasesRequestBuilder builder = client.admin().indices ().prepareAliases ().addAlias (indexName, alias);
IndicesAliasesResponse response = builder.execute ().actionGet ();
assertTrue(response.isAcknowledged ());
IndexAdminHelper helper = new IndexAdminHelperImpl (client);
List<AliasMetaData> aliases = helper.getIndexAliases (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 ());
}
示例7: testGetIndexNameForAlias
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的package包/类
@Test
public void testGetIndexNameForAlias() throws IndexAdminException{
//Create index
final CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(indexName);
@SuppressWarnings ("unused")
CreateIndexResponse createIndexResponse = createIndexRequestBuilder.execute().actionGet();
//Put the alias
String alias = "test_alias";
IndicesAliasesRequestBuilder builder = client.admin().indices ().prepareAliases ().addAlias (indexName, alias);
IndicesAliasesResponse response = builder.execute ().actionGet ();
assertTrue(response.isAcknowledged ());
IndexAdminHelper helper = new IndexAdminHelperImpl (client);
String theIndexName = helper.getIndexNameForAlias(alias);
log.debug(String.format("**** The index name: %s", theIndexName));
assertEquals (indexName, theIndexName);
}
示例8: testPutIndexAlias
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的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 ());
}
示例9: createAlias
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的package包/类
/**
* Create an alias if needed
* @param alias
* @param index
* @throws Exception
*/
private void createAlias(String alias, String index) throws Exception {
if (logger.isTraceEnabled()){
logger.trace("createAlias("+alias+","+index+")");
}
checkClient();
IndicesAliasesResponse response = client.admin().indices().prepareAliases().addAlias(index, alias).execute().actionGet();
if (!response.isAcknowledged()){
throw new Exception("Could not define alias [" + alias + "] for index [" + index + "].");
}
if (logger.isTraceEnabled()){
logger.trace("/createAlias("+alias+","+index+")");
}
}
示例10: handleRequest
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
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.removeAlias(indices, aliases);
indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));
client.admin().indices().aliases(indicesAliasesRequest, new AcknowledgedRestListener<IndicesAliasesResponse>(channel));
}
示例11: addIndexAlias
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的package包/类
/**
* 给索引添加别名
*
* @param index
* @param alias
* @return
*/
public boolean addIndexAlias(String index, String alias) {
try {
IndicesAliasesResponse resp = client.admin().indices().prepareAliases().addAlias(index, alias).get();
return resp.isAcknowledged();
}
catch (Exception e) {
return false;
}
}
示例12: removeIndexAlias
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的package包/类
/**
* 给索引删除别名
*
* @param index
* @param alias
* @return
*/
public boolean removeIndexAlias(String index, String alias) {
try {
IndicesAliasesResponse resp = client.admin().indices().prepareAliases().removeAlias(index, alias).get();
return resp.isAcknowledged();
}
catch (Exception e) {
return false;
}
}
示例13: execute
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的package包/类
/**
* Creates a view (elasticsearch alias) with given name and query
* @param sql
* @param create
* @param index
* @return
* @throws SQLException
*/
public int execute(String sql, CreateView create, String index) throws SQLException{
String alias = create.getName().toString();
alias = Heading.findOriginal(sql, alias, "\\s+view\\s+", "\\s+as\\s+");
QueryBody queryBody = create.getQuery().getQueryBody();
if(!(queryBody instanceof QuerySpecification)) throw new SQLException("Statement does not contain expected query specifiction");
QuerySpecification querySpec = (QuerySpecification)queryBody;
if(!querySpec.getFrom().isPresent()) throw new SQLException("Add atleast one INDEX to the query to create the view from");
QueryState state = new BasicQueryState(sql, new Heading(), props);
List<QuerySource> relations = new RelationParser().process(querySpec.getFrom().get(), null);
String[] indices = new String[relations.size()];
for(int i=0; i<relations.size(); i++) indices[i] = relations.get(i).getSource();
new SelectParser().process(querySpec.getSelect(), state);
IndicesAliasesResponse response;
if(querySpec.getWhere().isPresent()){
QueryBuilder query = new WhereParser().process(querySpec.getWhere().get(), state).getQuery();
response = client.admin().indices().prepareAliases().addAlias(indices, alias, query).execute().actionGet();
}else{
response = client.admin().indices().prepareAliases().addAlias(indices, alias).execute().actionGet();
}
if(!response.isAcknowledged()) throw new SQLException("Elasticsearch failed to create the specified alias");
this.statement.getConnection().getTypeMap(); // trigger a reload of the table&column set for the connection
return 0; // the number of altered rows
}
示例14: createIndexAlias
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的package包/类
@Override
public void createIndexAlias(String indexName, String aliasName) {
IndicesAliasesResponse response = indicesAdminClient().prepareAliases().addAlias(indexName, aliasName).execute()
.actionGet();
log.info("Index: " + indexName + ", isAcknowledged: " + response.isAcknowledged());
}
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:8,代码来源:DefaultElasticsearchIndexHelper.java
示例15: removeIndexAlias
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; //导入依赖的package包/类
@Override
public void removeIndexAlias(String indexName, String aliasName) {
IndicesAliasesResponse response = indicesAdminClient().prepareAliases().removeAlias(indexName, aliasName)
.execute().actionGet();
log.info("Index: " + indexName + ", isAcknowledged: " + response.isAcknowledged());
}
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:8,代码来源:DefaultElasticsearchIndexHelper.java