Search in sources :

Example 1 with MultiSearchRequest

use of org.elasticsearch.action.search.MultiSearchRequest in project elasticsearch by elastic.

the class RestMultiSearchAction method parseRequest.

/**
     * Parses a {@link RestRequest} body and returns a {@link MultiSearchRequest}
     */
public static MultiSearchRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex) throws IOException {
    MultiSearchRequest multiRequest = new MultiSearchRequest();
    if (restRequest.hasParam("max_concurrent_searches")) {
        multiRequest.maxConcurrentSearchRequests(restRequest.paramAsInt("max_concurrent_searches", 0));
    }
    parseMultiLineRequest(restRequest, multiRequest.indicesOptions(), allowExplicitIndex, (searchRequest, parser) -> {
        try {
            final QueryParseContext queryParseContext = new QueryParseContext(parser);
            searchRequest.source(SearchSourceBuilder.fromXContent(queryParseContext));
            multiRequest.add(searchRequest);
        } catch (IOException e) {
            throw new ElasticsearchParseException("Exception when parsing search request", e);
        }
    });
    return multiRequest;
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) IOException(java.io.IOException)

Example 2 with MultiSearchRequest

use of org.elasticsearch.action.search.MultiSearchRequest in project camel by apache.

the class ElasticsearchActionRequestConverter method toMultiSearchRequest.

@SuppressWarnings("unchecked")
@Converter
public static MultiSearchRequest toMultiSearchRequest(Object document, Exchange exchange) {
    List<SearchRequest> items = (List<SearchRequest>) document;
    MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
    Iterator<SearchRequest> it = items.iterator();
    while (it.hasNext()) {
        SearchRequest item = it.next();
        multiSearchRequest.add(item);
    }
    return multiSearchRequest;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) List(java.util.List) Converter(org.apache.camel.Converter)

Example 3 with MultiSearchRequest

use of org.elasticsearch.action.search.MultiSearchRequest in project camel by apache.

the class ElasticsearchActionRequestConverter method toMultiSearchRequest.

@Converter
public static MultiSearchRequest toMultiSearchRequest(Object document, Exchange exchange) {
    List<SearchRequest> items = (List<SearchRequest>) document;
    MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
    Iterator<SearchRequest> it = items.iterator();
    while (it.hasNext()) {
        SearchRequest item = it.next();
        multiSearchRequest.add(item);
    }
    return multiSearchRequest;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) List(java.util.List) Converter(org.apache.camel.Converter)

Example 4 with MultiSearchRequest

use of org.elasticsearch.action.search.MultiSearchRequest in project graylog2-server by Graylog2.

the class ElasticsearchClient method msearch.

public List<MultiSearchResponse.Item> msearch(List<SearchRequest> searchRequests, String errorMessage) {
    final MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
    searchRequests.forEach(multiSearchRequest::add);
    final MultiSearchResponse result = this.execute((c, requestOptions) -> c.msearch(multiSearchRequest, requestOptions), errorMessage);
    return Streams.stream(result).collect(Collectors.toList());
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) MultiSearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchRequest)

Example 5 with MultiSearchRequest

use of org.elasticsearch.action.search.MultiSearchRequest in project graylog2-server by Graylog2.

the class ElasticsearchClient method search.

public SearchResponse search(SearchRequest searchRequest, String errorMessage) {
    final MultiSearchRequest multiSearchRequest = new MultiSearchRequest().add(searchRequest);
    final MultiSearchResponse result = this.execute((c, requestOptions) -> c.msearch(multiSearchRequest, requestOptions), errorMessage);
    return firstResponseFrom(result, errorMessage);
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) MultiSearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchRequest)

Aggregations

MultiSearchRequest (org.elasticsearch.action.search.MultiSearchRequest)6 List (java.util.List)4 SearchRequest (org.elasticsearch.action.search.SearchRequest)4 ArrayList (java.util.ArrayList)2 Converter (org.apache.camel.Converter)2 Message (org.apache.camel.Message)2 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)2 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)2 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)2 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)2 GetRequest (org.elasticsearch.action.get.GetRequest)2 MultiGetRequest (org.elasticsearch.action.get.MultiGetRequest)2 IndexRequest (org.elasticsearch.action.index.IndexRequest)2 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)2 MultiSearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchRequest)2 MultiSearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse)2 IOException (java.io.IOException)1 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)1 ExistsRequest (org.elasticsearch.action.exists.ExistsRequest)1 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)1