org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PluginClient.java    From openshift-elasticsearch-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 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) {
    return execute(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            boolean acknowledged = false;
            if (aliases.isEmpty()) {
                LOGGER.trace("The alias map is empty.  Nothing to do");
                return acknowledged;
            }
            IndicesAliasesRequestBuilder builder = client.admin().indices().prepareAliases();
            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;
        }
    });
}
 
Example #2
Source File: RestIndexDeleteAliasesAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #3
Source File: ESClient.java    From uavstack with Apache License 2.0 5 votes vote down vote up
/**
 * 给索引添加别名
 * 
 * @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;
    }
}
 
Example #4
Source File: ESClient.java    From uavstack with Apache License 2.0 5 votes vote down vote up
/**
 * 给索引删除别名
 * 
 * @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;
    }
}
 
Example #5
Source File: ESUpdateState.java    From sql4es with Apache License 2.0 5 votes vote down vote up
/**
 * 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
}
 
Example #6
Source File: UpdateIndicesAliasesRequestBuilder.java    From elasticshell with Apache License 2.0 5 votes vote down vote up
@Override
protected XContentBuilder toXContent(IndicesAliasesRequest request, IndicesAliasesResponse response, XContentBuilder builder) throws IOException {
    builder.startObject()
            .field(Fields.OK, true)
            .field(Fields.ACKNOWLEDGED, response.isAcknowledged())
            .endObject();
    return builder;
}
 
Example #7
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<IndicesAliasesResponse> aliases(final IndicesAliasesRequest request) {
    return execute(IndicesAliasesAction.INSTANCE, request);
}
 
Example #8
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void aliases(final IndicesAliasesRequest request, final ActionListener<IndicesAliasesResponse> listener) {
    execute(IndicesAliasesAction.INSTANCE, request, listener);
}
 
Example #9
Source File: RestIndexPutAliasAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
    String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    String alias = request.param("name");
    Map<String, Object> filter = null;
    String routing = null;
    String indexRouting = null;
    String searchRouting = null;

    if (request.hasContent()) {
        try (XContentParser parser = XContentFactory.xContent(request.content()).createParser(request.content())) {
            XContentParser.Token token = parser.nextToken();
            if (token == null) {
                throw new IllegalArgumentException("No index alias is specified");
            }
            String currentFieldName = null;
            while ((token = parser.nextToken()) != null) {
                if (token == XContentParser.Token.FIELD_NAME) {
                    currentFieldName = parser.currentName();
                } else if (token.isValue()) {
                    if ("index".equals(currentFieldName)) {
                        indices = Strings.splitStringByCommaToArray(parser.text());
                    } else if ("alias".equals(currentFieldName)) {
                        alias = parser.text();
                    } else if ("routing".equals(currentFieldName)) {
                        routing = parser.textOrNull();
                    } else if ("indexRouting".equals(currentFieldName) || "index-routing".equals(currentFieldName) || "index_routing".equals(currentFieldName)) {
                        indexRouting = parser.textOrNull();
                    } else if ("searchRouting".equals(currentFieldName) || "search-routing".equals(currentFieldName) || "search_routing".equals(currentFieldName)) {
                        searchRouting = parser.textOrNull();
                    }
                } else if (token == XContentParser.Token.START_OBJECT) {
                    if ("filter".equals(currentFieldName)) {
                        filter = parser.mapOrdered();
                    }
                }
            }
        }
    }

    IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
    indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
    String[] aliases = new String[]{alias};
    IndicesAliasesRequest.AliasActions aliasAction = new AliasActions(AliasAction.Type.ADD, indices, aliases);
    indicesAliasesRequest.addAliasAction(aliasAction);
    indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));


    if (routing != null) {
        aliasAction.routing(routing);
    }
    if (searchRouting != null) {
        aliasAction.searchRouting(searchRouting);
    }
    if (indexRouting != null) {
        aliasAction.indexRouting(indexRouting);
    }
    if (filter != null) {
        aliasAction.filter(filter);
    }
    client.admin().indices().aliases(indicesAliasesRequest, new AcknowledgedRestListener<IndicesAliasesResponse>(channel));
}
 
Example #10
Source File: UpdateIndicesAliasesRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected ActionFuture<IndicesAliasesResponse> doExecute(IndicesAliasesRequest request) {
    return client.admin().indices().aliases(request);
}
 
Example #11
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Allows to add/remove aliases from indices.
 *
 * @param request The index aliases request
 * @return The result future
 * @see Requests#indexAliasesRequest()
 */
ActionFuture<IndicesAliasesResponse> aliases(IndicesAliasesRequest request);
 
Example #12
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Allows to add/remove aliases from indices.
 *
 * @param request  The index aliases request
 * @param listener A listener to be notified with a result
 * @see Requests#indexAliasesRequest()
 */
void aliases(IndicesAliasesRequest request, ActionListener<IndicesAliasesResponse> listener);