Package org.elasticsearch.action.suggest

Examples of org.elasticsearch.action.suggest.SuggestRequest


public class SuggestRequestBuilder<JsonInput, JsonOutput> extends AbstractRequestBuilderJsonOutput<SuggestRequest, SuggestResponse, JsonInput, JsonOutput> {

    final SuggestBuilder suggest = new SuggestBuilder();

    public SuggestRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
        super(client, new SuggestRequest(), jsonToString, stringToJson);
    }
View Full Code Here


        return this;
    }

    @Override
    protected SuggestRequest request() {
        SuggestRequest suggestRequest = super.request();
        try {
            XContentBuilder builder = XContentFactory.contentBuilder(Requests.CONTENT_TYPE);
            suggest.toXContent(builder, ToXContent.EMPTY_PARAMS);
            suggestRequest.suggest(builder.bytes());
        } catch (IOException e) {
            throw new ElasticSearchException("Unable to build suggestion request", e);
        }
        return suggestRequest;
    }
View Full Code Here

     * The suggest query has to be set using the JSON source using {@link org.elasticsearch.action.suggest.SuggestRequest#suggest(org.elasticsearch.common.bytes.BytesReference)}.
     * @param indices The indices to suggest from. Use <tt>null</tt> or <tt>_all</tt> to execute against all indices
     * @see org.elasticsearch.client.Client#suggest(org.elasticsearch.action.suggest.SuggestRequest)
     */
    public static SuggestRequest suggestRequest(String... indices) {
        return new SuggestRequest(indices);
    }
View Full Code Here

        controller.registerHandler(GET, "/{index}/_suggest", this);
    }

    @Override
    public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
        SuggestRequest suggestRequest = new SuggestRequest(Strings.splitStringByCommaToArray(request.param("index")));
        suggestRequest.indicesOptions(IndicesOptions.fromRequest(request, suggestRequest.indicesOptions()));
        suggestRequest.listenerThreaded(false);
        if (request.hasContent()) {
            suggestRequest.suggest(request.content(), request.contentUnsafe());
        } else {
            String source = request.param("source");
            if (source != null) {
                suggestRequest.suggest(source);
            } else {
                throw new ElasticsearchIllegalArgumentException("no content or source provided to execute suggestion");
            }
        }
        suggestRequest.routing(request.param("routing"));
        suggestRequest.preference(request.param("preference"));

        client.suggest(suggestRequest, new RestBuilderListener<SuggestResponse>(channel) {
            @Override
            public RestResponse buildResponse(SuggestResponse response, XContentBuilder builder) throws Exception {
                builder.startObject();
View Full Code Here

    @Test
    public void testSuggest() {
        String suggestAction = SuggestAction.NAME + "[s]";
        interceptTransportActions(suggestAction);

        SuggestRequest suggestRequest = new SuggestRequest(randomIndicesOrAliases());
        internalCluster().clientNodeClient().suggest(suggestRequest).actionGet();

        clearInterceptedActions();
        assertSameIndices(suggestRequest, suggestAction);
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.suggest.SuggestRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.