Java 类org.elasticsearch.action.search.SearchScrollRequest 实例源码

项目:elasticsearch_my    文件:RestSearchScrollAction.java   
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String scrollId = request.param("scroll_id");
    SearchScrollRequest searchScrollRequest = new SearchScrollRequest();
    searchScrollRequest.scrollId(scrollId);
    String scroll = request.param("scroll");
    if (scroll != null) {
        searchScrollRequest.scroll(new Scroll(parseTimeValue(scroll, null, "scroll")));
    }

    request.withContentOrSourceParamParserOrNull(xContentParser -> {
        if (xContentParser != null) {
            // NOTE: if rest request with xcontent body has request parameters, these parameters override xcontent values
            try {
                buildFromContent(xContentParser, searchScrollRequest);
            } catch (IOException e) {
                throw new IllegalArgumentException("Failed to parse request body", e);
            }
        }});
    return channel -> client.searchScroll(searchScrollRequest, new RestStatusToXContentListener<>(channel));
}
项目:elasticsearch_my    文件:RestSearchScrollAction.java   
public static void buildFromContent(XContentParser parser, SearchScrollRequest searchScrollRequest) throws IOException {
    if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
        throw new IllegalArgumentException("Malformed content, must start with an object");
    } else {
        XContentParser.Token token;
        String currentFieldName = null;
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                currentFieldName = parser.currentName();
            } else if ("scroll_id".equals(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
                searchScrollRequest.scrollId(parser.text());
            } else if ("scroll".equals(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
                searchScrollRequest.scroll(new Scroll(TimeValue.parseTimeValue(parser.text(), null, "scroll")));
            } else {
                throw new IllegalArgumentException("Unknown parameter [" + currentFieldName
                        + "] in request body or parameter is of the wrong type[" + token + "] ");
            }
        }
    }
}
项目:Elasticsearch    文件:RestSearchScrollAction.java   
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    String scrollId = request.param("scroll_id");
    SearchScrollRequest searchScrollRequest = new SearchScrollRequest();
    searchScrollRequest.scrollId(scrollId);
    String scroll = request.param("scroll");
    if (scroll != null) {
        searchScrollRequest.scroll(new Scroll(parseTimeValue(scroll, null, "scroll")));
    }

    if (RestActions.hasBodyContent(request)) {
        XContentType type = XContentFactory.xContentType(RestActions.getRestContent(request));
        if (type == null) {
            if (scrollId == null) {
                scrollId = RestActions.getRestContent(request).toUtf8();
                searchScrollRequest.scrollId(scrollId);
            }
        } else {
            // NOTE: if rest request with xcontent body has request parameters, these parameters override xcontent values
            buildFromContent(RestActions.getRestContent(request), searchScrollRequest);
        }
    }
    client.searchScroll(searchScrollRequest, new RestStatusToXContentListener<SearchResponse>(channel));
}
项目:Elasticsearch    文件:RestSearchScrollAction.java   
public static void buildFromContent(BytesReference content, SearchScrollRequest searchScrollRequest) {
    try (XContentParser parser = XContentHelper.createParser(content)) {
        if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
            throw new IllegalArgumentException("Malforrmed content, must start with an object");
        } else {
            XContentParser.Token token;
            String currentFieldName = null;
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                if (token == XContentParser.Token.FIELD_NAME) {
                    currentFieldName = parser.currentName();
                } else if ("scroll_id".equals(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
                    searchScrollRequest.scrollId(parser.text());
                } else if ("scroll".equals(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
                    searchScrollRequest.scroll(new Scroll(TimeValue.parseTimeValue(parser.text(), null, "scroll")));
                } else {
                    throw new IllegalArgumentException("Unknown parameter [" + currentFieldName + "] in request body or parameter is of the wrong type[" + token + "] ");
                }
            }
        }
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to parse request body", e);
    }
}
项目:elasticsearch_my    文件:ClientScrollableHitSource.java   
@Override
protected void doStartNextScroll(String scrollId, TimeValue extraKeepAlive, Consumer<? super Response> onResponse) {
    searchWithRetry(listener -> {
        SearchScrollRequest request = new SearchScrollRequest();
        // Add the wait time into the scroll timeout so it won't timeout while we wait for throttling
        request.scrollId(scrollId).scroll(timeValueNanos(firstSearchRequest.scroll().keepAlive().nanos() + extraKeepAlive.nanos()));
        client.searchScroll(request, listener);
    }, r -> consume(r, onResponse));
}
项目:elasticsearch_my    文件:RestSearchScrollActionTests.java   
public void testParseSearchScrollRequest() throws Exception {
    XContentParser content = createParser(XContentFactory.jsonBuilder()
        .startObject()
            .field("scroll_id", "SCROLL_ID")
            .field("scroll", "1m")
        .endObject());

    SearchScrollRequest searchScrollRequest = new SearchScrollRequest();
    RestSearchScrollAction.buildFromContent(content, searchScrollRequest);

    assertThat(searchScrollRequest.scrollId(), equalTo("SCROLL_ID"));
    assertThat(searchScrollRequest.scroll().keepAlive(), equalTo(TimeValue.parseTimeValue("1m", null, "scroll")));
}
项目:elasticsearch_my    文件:RestSearchScrollActionTests.java   
public void testParseSearchScrollRequestWithUnknownParamThrowsException() throws Exception {
    SearchScrollRequest searchScrollRequest = new SearchScrollRequest();
    XContentParser invalidContent = createParser(XContentFactory.jsonBuilder()
            .startObject()
                .field("scroll_id", "value_2")
                .field("unknown", "keyword")
            .endObject());

    Exception e = expectThrows(IllegalArgumentException.class,
            () -> RestSearchScrollAction.buildFromContent(invalidContent, searchScrollRequest));
    assertThat(e.getMessage(), startsWith("Unknown parameter [unknown]"));
}
项目:Elasticsearch    文件:ShardFetchRequest.java   
public ShardFetchRequest(SearchScrollRequest request, long id, IntArrayList list, ScoreDoc lastEmittedDoc) {
    super(request);
    this.id = id;
    this.docIds = list.buffer;
    this.size = list.size();
    this.lastEmittedDoc = lastEmittedDoc;
}
项目:elasticsearch-vectorize    文件:RestSearchVectorizeScrollAction.java   
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    String scrollId = request.param("scroll_id");
    SearchScrollRequest searchScrollRequest = new SearchScrollRequest();
    searchScrollRequest.scrollId(scrollId);
    String scroll = request.param("scroll");
    if (scroll != null) {
        searchScrollRequest.scroll(new Scroll(parseTimeValue(scroll, null, "scroll")));
    }

    if (RestActions.hasBodyContent(request)) {
        XContentType type = XContentFactory.xContentType(RestActions.getRestContent(request));
        if (type == null) {
            if (scrollId == null) {
                scrollId = RestActions.getRestContent(request).toUtf8();
                searchScrollRequest.scrollId(scrollId);
            }
        } else {
            // NOTE: if rest request with xcontent body has request parameters, these parameters override xcontent values
            RestSearchScrollAction.buildFromContent(RestActions.getRestContent(request), searchScrollRequest);
        }
    }

    final String sparseFormat = request.param("sparse_format", "dict");
    client.searchScroll(searchScrollRequest, new RestBuilderListener<SearchResponse>(channel) {
        @Override
        public RestResponse buildResponse(SearchResponse resp, XContentBuilder builder) throws Exception {
            SearchVectorizeResponse searchVectorizeResponse = new SearchVectorizeResponse(resp);
            searchVectorizeResponse.setFormat(sparseFormat);
            searchVectorizeResponse.toXContent(builder, ToXContent.EMPTY_PARAMS);
            return new BytesRestResponse(OK, builder);
        }
    });
}
项目:elasticsearch-http    文件:SearchScrollActionHandler.java   
public void execute(SearchScrollRequest request, final ActionListener<SearchResponse> listener) {
    logger.debug("Search scroll request {}", request);
    try {
        ActionRequestValidationException validation = request.validate();
        if(validation != null && !validation.validationErrors().isEmpty()) {
            throw validation;
        }

        RequestUriBuilder uriBuilder = new RequestUriBuilder()
                .addEndpoint("_search/scroll");

        if (request.scroll() != null) {
            uriBuilder.addQueryParameter("scroll", request.scroll().keepAlive().toString());
        }
        uriBuilder.addQueryParameter("scroll_id", request.scrollId());

        httpClient.getHttpClient().submit(HttpClientRequest.createGet(uriBuilder.toString()))
                .flatMap(ErrorHandler.AS_FUNC)
                .flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<SearchResponse>>() {
                    @Override
                    public Observable<SearchResponse> call(HttpClientResponse<ByteBuf> response) {
                        return response.getContent().flatMap(new Func1<ByteBuf, Observable<SearchResponse>>() {
                            @Override
                            public Observable<SearchResponse> call(ByteBuf byteBuf) {
                                return SearchResponse.parse(byteBuf);
                            }
                        });
                    }
                })
                .single()
                .subscribe(new ListenerCompleterObserver<>(listener));

    } catch (Exception e) {
        listener.onFailure(e);
    }
}
项目:elasticsearch-http    文件:SearchScrollActionHandlerTest.java   
@Test
public void should_fail_when_scroll_id_is_missing() throws Exception {
    try {
        httpClient.searchScroll(new SearchScrollRequest()).get();
        fail();
    } catch (ExecutionException e) {
        Assertions.assertThat(e).hasCauseInstanceOf(ActionRequestValidationException.class);
        Assertions.assertThat(e.getCause()).hasMessageContaining("scrollId is missing");
    }
}
项目:metamodel    文件:ElasticSearchRestClient.java   
ActionResponse execute(final ActionRequest request) throws IOException {
    if (request instanceof BulkRequest) {
        return bulk((BulkRequest) request);
    } else if (request instanceof IndexRequest) {
        return index((IndexRequest) request);
    } else if (request instanceof DeleteRequest) {
        return delete((DeleteRequest) request);
    } else if (request instanceof ClearScrollRequest) {
        return clearScroll((ClearScrollRequest) request);
    } else if (request instanceof SearchScrollRequest) {
        return searchScroll((SearchScrollRequest) request);
    }

    return null;
}
项目:elasticsearch_my    文件:InternalScrollSearchRequest.java   
public InternalScrollSearchRequest(SearchScrollRequest request, long id) {
    this.id = id;
    this.scroll = request.scroll();
}
项目:elasticsearch_my    文件:AbstractClient.java   
@Override
public ActionFuture<SearchResponse> searchScroll(final SearchScrollRequest request) {
    return execute(SearchScrollAction.INSTANCE, request);
}
项目:elasticsearch_my    文件:AbstractClient.java   
@Override
public void searchScroll(final SearchScrollRequest request, final ActionListener<SearchResponse> listener) {
    execute(SearchScrollAction.INSTANCE, request, listener);
}
项目:Elasticsearch    文件:InternalScrollSearchRequest.java   
public InternalScrollSearchRequest(SearchScrollRequest request, long id) {
    super(request);
    this.id = id;
    this.scroll = request.scroll();
}
项目:elasticsearch-java-client    文件:DummyClient.java   
@Override
public ActionFuture<SearchResponse> searchScroll(SearchScrollRequest request) {
    // TODO Auto-generated method stub
    return null;
}
项目:elasticsearch-java-client    文件:DummyClient.java   
@Override
public void searchScroll(SearchScrollRequest request, ActionListener<SearchResponse> listener) {
    // TODO Auto-generated method stub

}
项目:elasticsearch-http    文件:HttpClient.java   
public void searchScroll(SearchScrollRequest request, ActionListener<SearchResponse> listener) {
    searchScrollActionHandler.execute(request, listener);
}
项目:elasticsearch-http    文件:HttpClient.java   
public Future<SearchResponse> searchScroll(SearchScrollRequest request) {
    PlainActionFuture<SearchResponse> future = PlainActionFuture.newFuture();
    searchScroll(request, future);
    return future;
}
项目:metamodel    文件:ElasticSearchRestDataSet.java   
@Override
protected SearchResponse scrollSearchResponse(final String scrollId) throws IOException {
    return _client.searchScroll(new SearchScrollRequest(scrollId).scroll(
            AbstractElasticSearchDataContext.TIMEOUT_SCROLL));
}
项目:elasticshell    文件:SearchScrollRequestBuilder.java   
public SearchScrollRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
    super(client, new SearchScrollRequest(), jsonToString, stringToJson);
}
项目:elasticshell    文件:SearchScrollRequestBuilder.java   
@Override
protected ActionFuture<SearchResponse> doExecute(SearchScrollRequest request) {
    return client.searchScroll(request);
}
项目:elasticshell    文件:SearchScrollRequestBuilder.java   
@Override
protected XContentBuilder toXContent(SearchScrollRequest request, SearchResponse response, XContentBuilder builder) throws IOException {
    return super.toXContent(request, response, builder).endObject();
}
项目:elasticsearch_my    文件:Client.java   
/**
 * A search scroll request to continue searching a previous scrollable search request.
 *
 * @param request The search scroll request
 * @return The result future
 * @see Requests#searchScrollRequest(String)
 */
ActionFuture<SearchResponse> searchScroll(SearchScrollRequest request);
项目:elasticsearch_my    文件:Client.java   
/**
 * A search scroll request to continue searching a previous scrollable search request.
 *
 * @param request  The search scroll request
 * @param listener A listener to be notified of the result
 * @see Requests#searchScrollRequest(String)
 */
void searchScroll(SearchScrollRequest request, ActionListener<SearchResponse> listener);
项目:elasticsearch_my    文件:Requests.java   
/**
 * Creates a search scroll request allowing to continue searching a previous search request.
 *
 * @param scrollId The scroll id representing the scrollable search
 * @return The search scroll request
 * @see org.elasticsearch.client.Client#searchScroll(org.elasticsearch.action.search.SearchScrollRequest)
 */
public static SearchScrollRequest searchScrollRequest(String scrollId) {
    return new SearchScrollRequest(scrollId);
}
项目:Elasticsearch    文件:Requests.java   
/**
 * Creates a search scroll request allowing to continue searching a previous search request.
 *
 * @param scrollId The scroll id representing the scrollable search
 * @return The search scroll request
 * @see org.elasticsearch.client.Client#searchScroll(org.elasticsearch.action.search.SearchScrollRequest)
 */
public static SearchScrollRequest searchScrollRequest(String scrollId) {
    return new SearchScrollRequest(scrollId);
}