org.elasticsearch.action.ActionFuture Java Examples

The following examples show how to use org.elasticsearch.action.ActionFuture. 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: InternalEsClient.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * 非同期でドキュメントを検索. <br />
 * Queryの指定方法をMapで直接記述せずにQueryBuilderにするため、非推奨とする.
 * @param index インデックス名
 * @param routingId routingId
 * @param query クエリ情報
 * @return 非同期応答
 */
public ActionFuture<SearchResponse> asyncSearch(
        String index,
        String routingId,
        Map<String, Object> query) {
    SearchRequest req = new SearchRequest(index).searchType(SearchType.DEFAULT);
    if (query != null) {
        req.source(query);
    }
    if (routingFlag) {
        req = req.routing(routingId);
    }
    ActionFuture<SearchResponse> ret = esTransportClient.search(req);
    this.fireEvent(Event.afterRequest, index, null, null, JSONObject.toJSONString(query), "Search");
    return ret;
}
 
Example #2
Source File: ElasticsearchAssertions.java    From crate with Apache License 2.0 6 votes vote down vote up
public static void assertThrows(ActionFuture future, RestStatus status, String extraInfo) {
    boolean fail = false;
    extraInfo = extraInfo == null || extraInfo.isEmpty() ? "" : extraInfo + ": ";
    extraInfo += "expected a " + status + " status exception to be thrown";

    try {
        future.actionGet();
        fail = true;
    } catch (Exception e) {
        assertThat(extraInfo, ExceptionsHelper.status(e), equalTo(status));
    }
    // has to be outside catch clause to get a proper message
    if (fail) {
        throw new AssertionError(extraInfo);
    }
}
 
Example #3
Source File: InternalEsClient.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * 非同期でドキュメントを検索.
 * @param index インデックス名
 * @param type タイプ名
 * @param routingId routingId
 * @param query クエリ情報
 * @return 非同期応答
 */
public ActionFuture<SearchResponse> asyncSearch(
        String index,
        String type,
        String routingId,
        Map<String, Object> query) {
    SearchRequest req = new SearchRequest(index).types(type).searchType(SearchType.DEFAULT);
    if (query != null) {
        req.source(query);
    }
    if (routingFlag) {
        req = req.routing(routingId);
    }
    ActionFuture<SearchResponse> ret = esTransportClient.search(req);
    this.fireEvent(Event.afterRequest, index, type, null, JSONObject.toJSONString(query), "Search");
    return ret;
}
 
Example #4
Source File: InternalEsClient.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * 非同期でドキュメントを検索.
 * @param index インデックス名
 * @param routingId routingId
 * @param query クエリ情報
 * @return 非同期応答
 */
public ActionFuture<SearchResponse> asyncSearch(
        String index,
        String routingId,
        QueryBuilder query) {
    SearchRequest req = new SearchRequest(index).searchType(SearchType.DEFAULT);

    String queryString = "null";
    if (query != null) {
        req.source(new SearchSourceBuilder().query(query));
        queryString = query.buildAsBytes().toUtf8();
    }
    if (routingFlag) {
        req = req.routing(routingId);
    }
    ActionFuture<SearchResponse> ret = esTransportClient.search(req);
    this.fireEvent(Event.afterRequest, index, null, null, queryString, "Search");
    return ret;
}
 
Example #5
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
public ActionFuture<SearchResponse> asyncSearch(
        String index,
        String type,
        String routingId,
        SearchSourceBuilder builder) {
    throwException();
    return super.asyncSearch(index, type, routingId, builder);
}
 
Example #6
Source File: ElasticsearchAssertions.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Run future.actionGet() and check that it throws an exception of the right type, optionally checking the exception's rest status
 *
 * @param exceptionClass expected exception class
 * @param status         {@link org.elasticsearch.rest.RestStatus} to check for. Can be null to disable the check
 * @param extraInfo      extra information to add to the failure message. Can be null.
 */
public static <E extends Throwable> void assertThrows(ActionFuture future, Class<E> exceptionClass,
        @Nullable RestStatus status, @Nullable String extraInfo) {
    boolean fail = false;
    extraInfo = extraInfo == null || extraInfo.isEmpty() ? "" : extraInfo + ": ";
    extraInfo += "expected a " + exceptionClass + " exception to be thrown";

    if (status != null) {
        extraInfo += " with status [" + status + "]";
    }

    try {
        future.actionGet();
        fail = true;

    } catch (ElasticsearchException esException) {
        assertThat(extraInfo, esException.unwrapCause(), instanceOf(exceptionClass));
        if (status != null) {
            assertThat(extraInfo, ExceptionsHelper.status(esException), equalTo(status));
        }
    } catch (Exception e) {
        assertThat(extraInfo, e, instanceOf(exceptionClass));
        if (status != null) {
            assertThat(extraInfo, ExceptionsHelper.status(e), equalTo(status));
        }
    }
    // has to be outside catch clause to get a proper message
    if (fail) {
        throw new AssertionError(extraInfo);
    }
}
 
Example #7
Source File: XPackBaseDemo.java    From elasticsearch-full with Apache License 2.0 5 votes vote down vote up
@Test
public void testClientConnection() throws Exception {
    AnalyzeRequest analyzeRequest = new AnalyzeRequest();
    analyzeRequest.text("美女");
    ActionFuture<AnalyzeResponse> analyzeResponseActionFuture = client.admin().indices().analyze(analyzeRequest);
    List<AnalyzeResponse.AnalyzeToken> analyzeTokens =  analyzeResponseActionFuture.actionGet().getTokens();
    for (AnalyzeResponse.AnalyzeToken analyzeToken  : analyzeTokens){
        System.out.println(analyzeToken.getTerm());
    }
}
 
Example #8
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
public ActionFuture<IndexResponse> asyncIndex(String index,
        String type,
        String id,
        String routingId,
        Map<String, Object> data,
        OpType opType,
        long version) {
    throwException();
    return super.asyncIndex(index, type, id, routingId, data, opType, version);
}
 
Example #9
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
public ActionFuture<SearchResponse> asyncSearch(
        String index,
        String type,
        String routingId,
        Map<String, Object> query) {
    throwException();
    return super.asyncSearch(index, type, routingId, query);
}
 
Example #10
Source File: AbstractESTest.java    From elasticsearch-migration with Apache License 2.0 5 votes vote down vote up
@SneakyThrows
protected boolean checkDocumentExists(String indexName, String type, String id) {
    final ActionFuture<GetResponse> response = client.get(new GetRequest(indexName, type, id));
    client.admin().indices().prepareFlush(indexName).setWaitIfOngoing(true).setForce(true).execute().get();
    final GetResponse getFields = response.get();

    assertThat("Response should be done", response.isDone(), is(true));
    return getFields.isExists();
}
 
Example #11
Source File: QuestionElasticSearchIndexBuilder.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * This is a new search that accepts additionalSearchInformation. We need it for our complex question searches.
 * We have duplicated the methods that need this parameter, like prepareSearchRequest
 */
public SearchResponse search(String searchTerms, List<String> references, List<String> siteIds, int start, int end, Map<String,String> additionalSearchInformation) {
    final Pair<SearchRequestBuilder,QueryBuilder> searchBuilders = prepareSearchRequest(searchTerms, references, siteIds, start, end, additionalSearchInformation);
    final SearchRequestBuilder searchRequestBuilder = searchBuilders.getLeft();
    final QueryBuilder queryBuilder = searchBuilders.getRight();

    getLog().debug("Search request from index builder [" + getName() + "]: " + searchRequestBuilder.toString());

    ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest(indexName);
    QuerySourceBuilder querySourceBuilder = new QuerySourceBuilder().setQuery(queryBuilder);
    validateQueryRequest.source(querySourceBuilder);
    validateQueryRequest.explain(true);


    try {
        ActionFuture<ValidateQueryResponse> future = client.admin().indices().validateQuery(validateQueryRequest); // the client is org.elasticsearch.client.Client
        ValidateQueryResponse responseV = future.get(); // typical java future as response

        if (responseV.isValid()) {
            SearchResponse response = searchRequestBuilder.execute().actionGet();
            getLog().debug("Search request from index builder [" + getName() + "] took: " + response.getTook().format());
            eventTrackingService.post(eventTrackingService.newEvent(SearchService.EVENT_SEARCH,
                    SearchService.EVENT_SEARCH_REF + queryBuilder.toString(), true,
                    NotificationService.PREF_IMMEDIATE));

            return response;
        }else{
            return null;
        }
    }catch(Exception ex){
        return null;
    }

}
 
Example #12
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
public ActionFuture<SearchResponse> asyncSearch(
        String index,
        String routingId,
        Map<String, Object> query) {
    throwException();
    return super.asyncSearch(index, routingId, query);
}
 
Example #13
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
public ActionFuture<SearchResponse> asyncSearch(
        String index,
        String routingId,
        Map<String, Object> query) {
    throwException();
    return super.asyncSearch(index, routingId, query);
}
 
Example #14
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
public ActionFuture<IndexResponse> asyncIndex(String index,
        String type,
        String id,
        String routingId,
        Map<String, Object> data,
        OpType opType,
        long version) {
    throwException();
    return super.asyncIndex(index, type, id, routingId, data, opType, version);
}
 
Example #15
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
public ActionFuture<SearchResponse> asyncSearch(
        String index,
        String routingId,
        Map<String, Object> query) {
    throwException();
    return super.asyncSearch(index, routingId, query);
}
 
Example #16
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
public ActionFuture<SearchResponse> asyncSearch(
        String index,
        String routingId,
        Map<String, Object> query) {
    throwException();
    return super.asyncSearch(index, routingId, query);
}
 
Example #17
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
public ActionFuture<IndexResponse> asyncIndex(String index,
        String type,
        String id,
        String routingId,
        Map<String, Object> data,
        OpType opType,
        long version) {
    throwException();
    return super.asyncIndex(index, type, id, routingId, data, opType, version);
}
 
Example #18
Source File: ElasticsearchClientImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
@Override
public <RequestT extends ActionRequest, ResponseT extends ActionResponse,
    RequestBuilderT extends ActionRequestBuilder<RequestT, ResponseT, RequestBuilderT>> ActionFuture<ResponseT> execute(
    Action<RequestT, ResponseT, RequestBuilderT> action, RequestT request)
{
    return null;
}
 
Example #19
Source File: InternalEsClient.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * 非同期でドキュメントを検索.
 * @param index インデックス名
 * @param type タイプ名
 * @param routingId routingId
 * @param builder クエリ情報
 * @return 非同期応答
 */
public ActionFuture<SearchResponse> asyncSearch(
        String index,
        String type,
        String routingId,
        SearchSourceBuilder builder) {
    SearchRequest req = new SearchRequest(index).types(type).searchType(SearchType.DEFAULT).source(builder);
    if (routingFlag) {
        req = req.routing(routingId);
    }
    ActionFuture<SearchResponse> ret = esTransportClient.search(req);
    this.fireEvent(Event.afterRequest, index, type, null,
            new String(builder.buildAsBytes().toBytes()), "Search");
    return ret;
}
 
Example #20
Source File: InternalEsClient.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * 非同期でドキュメントを取得.
 * @param index インデックス名
 * @param type タイプ名
 * @param id ドキュメントのID
 * @param routingId routingId
 * @param realtime リアルタイムモードなら真
 * @return 非同期応答
 */
public ActionFuture<GetResponse> asyncGet(String index, String type, String id, String routingId,
        boolean realtime) {
    GetRequest req = new GetRequest(index, type, id);

    if (routingFlag) {
        req = req.routing(routingId);
    }

    req.realtime(realtime);
    ActionFuture<GetResponse> ret = esTransportClient.get(req);
    this.fireEvent(Event.afterRequest, index, type, id, null, "Get");
    return ret;
}
 
Example #21
Source File: InternalEsClient.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * 非同期でドキュメントを検索.
 * @param index インデックス名
 * @param query クエリ情報
 * @return 非同期応答
 */
public ActionFuture<SearchResponse> asyncSearch(String index, Map<String, Object> query) {
    SearchRequest req = new SearchRequest(index).searchType(SearchType.DEFAULT);
    if (query != null) {
        req.source(query);
    }
    ActionFuture<SearchResponse> ret = esTransportClient.search(req);
    this.fireEvent(Event.afterRequest, index, null, null, JSONObject.toJSONString(query), "Search");
    return ret;
}
 
Example #22
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
public ActionFuture<IndexResponse> asyncIndex(String index,
        String type,
        String id,
        String routingId,
        Map<String, Object> data,
        OpType opType,
        long version) {
    throwException();
    return super.asyncIndex(index, type, id, routingId, data, opType, version);
}
 
Example #23
Source File: EsRetryTest.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
public ActionFuture<IndexResponse> asyncIndex(String index,
        String type,
        String id,
        String routingId,
        Map<String, Object> data,
        OpType opType,
        long version) {
    throwException();
    return super.asyncIndex(index, type, id, routingId, data, opType, version);
}
 
Example #24
Source File: EsRetryTest.java    From io with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<GetResponse> asyncGet(String index, String type, String id, String routingId,
        boolean realtime) {
    throwException();
    return super.asyncGet(index, type, id, routingId, realtime);
}
 
Example #25
Source File: InternalEsClient.java    From io with Apache License 2.0 4 votes vote down vote up
/**
 * flushを行う.
 * @param index flush対象のindex名
 * @return 非同期応答
 */
public ActionFuture<FlushResponse> flushTransLog(String index) {
    ActionFuture<FlushResponse> ret = esTransportClient.admin().indices().flush(new FlushRequest(index));
    this.fireEvent(Event.afterRequest, index, null, null, null, "Flush");
    return ret;
}
 
Example #26
Source File: OptimizeRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected ActionFuture<OptimizeResponse> doExecute(OptimizeRequest request) {
    return client.admin().indices().optimize(request);
}
 
Example #27
Source File: FessEsClient.java    From fess with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<DeleteResponse> delete(final DeleteRequest request) {
    return client.delete(request);
}
 
Example #28
Source File: StatusRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected ActionFuture<IndicesStatusResponse> doExecute(IndicesStatusRequest request) {
    return client.admin().indices().status(request);
}
 
Example #29
Source File: ClientWithStats.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public ActionFuture<MultiTermVectorsResponse> multiTermVectors(MultiTermVectorsRequest request) {
	return wrapped.multiTermVectors(request);
}
 
Example #30
Source File: AbstractClient.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<RefreshResponse> refresh(final RefreshRequest request) {
    return execute(RefreshAction.INSTANCE, request);
}