Package org.elasticsearch.action.mlt

Examples of org.elasticsearch.action.mlt.MoreLikeThisRequest


     * @param index The index to load the document from
     * @return The more like this request
     * @see org.elasticsearch.client.Client#moreLikeThis(org.elasticsearch.action.mlt.MoreLikeThisRequest)
     */
    public static MoreLikeThisRequest moreLikeThisRequest(String index) {
        return new MoreLikeThisRequest(index);
    }
View Full Code Here


/**
*/
public class MoreLikeThisRequestBuilder extends BaseRequestBuilder<MoreLikeThisRequest, SearchResponse> {

    public MoreLikeThisRequestBuilder(Client client, String index, String type, String id) {
        super(client, new MoreLikeThisRequest(index).type(type).id(id));
    }
View Full Code Here

        controller.registerHandler(GET, "/{index}/{type}/{id}/_mlt", this);
        controller.registerHandler(POST, "/{index}/{type}/{id}/_mlt", this);
    }

    @Override public void handleRequest(final RestRequest request, final RestChannel channel) {
        MoreLikeThisRequest mltRequest = moreLikeThisRequest(request.param("index")).type(request.param("type")).id(request.param("id"));
        try {
            mltRequest.fields(request.paramAsStringArray("mlt_fields", null));
            mltRequest.percentTermsToMatch(request.paramAsFloat("percent_terms_to_match", -1));
            mltRequest.minTermFreq(request.paramAsInt("min_term_freq", -1));
            mltRequest.maxQueryTerms(request.paramAsInt("max_query_terms", -1));
            mltRequest.stopWords(request.paramAsStringArray("stop_words", null));
            mltRequest.minDocFreq(request.paramAsInt("min_doc_freq", -1));
            mltRequest.maxDocFreq(request.paramAsInt("max_doc_freq", -1));
            mltRequest.minWordLen(request.paramAsInt("min_word_len", -1));
            mltRequest.maxWordLen(request.paramAsInt("max_word_len", -1));
            mltRequest.boostTerms(request.paramAsFloat("boost_terms", -1));

            mltRequest.searchType(SearchType.fromString(request.param("search_type")));
            mltRequest.searchIndices(request.paramAsStringArray("search_indices", null));
            mltRequest.searchTypes(request.paramAsStringArray("search_types", null));
            mltRequest.searchQueryHint(request.param("search_query_hint"));
            mltRequest.searchSize(request.paramAsInt("search_size", mltRequest.searchSize()));
            mltRequest.searchFrom(request.paramAsInt("search_from", mltRequest.searchFrom()));
            String searchScroll = request.param("search_scroll");
            if (searchScroll != null) {
                mltRequest.searchScroll(new Scroll(parseTimeValue(searchScroll, null)));
            }
            if (request.hasContent()) {
                mltRequest.searchSource(request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength(), request.contentUnsafe());
            } else {
                String searchSource = request.param("search_source");
                if (searchSource != null) {
                    mltRequest.searchSource(searchSource);
                }
            }
        } catch (Exception e) {
            try {
                XContentBuilder builder = restContentBuilder(request);
View Full Code Here

*/
@SuppressWarnings("unused")
public class MoreLikeThisRequestBuilder<JsonInput, JsonOutput> extends AbstractRequestBuilderToXContent<MoreLikeThisRequest, SearchResponse, JsonInput, JsonOutput> {

    public MoreLikeThisRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson, String index) {
        super(client, new MoreLikeThisRequest(index), jsonToString, stringToJson);
    }
View Full Code Here

     * @param index The index to load the document from
     * @return The more like this request
     * @see org.elasticsearch.client.Client#moreLikeThis(org.elasticsearch.action.mlt.MoreLikeThisRequest)
     */
    public static MoreLikeThisRequest moreLikeThisRequest(String index) {
        return new MoreLikeThisRequest(index);
    }
View Full Code Here

        controller.registerHandler(POST, "/{index}/{type}/{id}/_mlt", this);
    }

    @Override
    public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
        MoreLikeThisRequest mltRequest = moreLikeThisRequest(request.param("index")).type(request.param("type")).id(request.param("id"));
        mltRequest.routing(request.param("routing"));

        mltRequest.listenerThreaded(false);
        //TODO the ParseField class that encapsulates the supported names used for an attribute
        //needs some work if it is to be used in a REST context like this too
        // See the MoreLikeThisQueryParser constants that hold the valid syntax
        mltRequest.fields(request.paramAsStringArray("mlt_fields", null));
        mltRequest.minimumShouldMatch(request.param("minimum_should_match", "0"));
        mltRequest.minTermFreq(request.paramAsInt("min_term_freq", -1));
        mltRequest.maxQueryTerms(request.paramAsInt("max_query_terms", -1));
        mltRequest.stopWords(request.paramAsStringArray("stop_words", null));
        mltRequest.minDocFreq(request.paramAsInt("min_doc_freq", -1));
        mltRequest.maxDocFreq(request.paramAsInt("max_doc_freq", -1));
        mltRequest.minWordLength(request.paramAsInt("min_word_len", request.paramAsInt("min_word_length", -1)));
        mltRequest.maxWordLength(request.paramAsInt("max_word_len", request.paramAsInt("max_word_length", -1)));
        mltRequest.boostTerms(request.paramAsFloat("boost_terms", -1));
        mltRequest.include(request.paramAsBoolean("include", false));

        mltRequest.searchType(SearchType.fromString(request.param("search_type")));
        mltRequest.searchIndices(request.paramAsStringArray("search_indices", null));
        mltRequest.searchTypes(request.paramAsStringArray("search_types", null));
        mltRequest.searchSize(request.paramAsInt("search_size", mltRequest.searchSize()));
        mltRequest.searchFrom(request.paramAsInt("search_from", mltRequest.searchFrom()));
        String searchScroll = request.param("search_scroll");
        if (searchScroll != null) {
            mltRequest.searchScroll(new Scroll(parseTimeValue(searchScroll, null)));
        }
        if (request.hasContent()) {
            mltRequest.searchSource(request.content(), request.contentUnsafe());
        } else {
            String searchSource = request.param("search_source");
            if (searchSource != null) {
                mltRequest.searchSource(searchSource);
            }
        }

        client.moreLikeThis(mltRequest, new RestToXContentListener<SearchResponse>(channel));
    }
View Full Code Here

        assertAcked(prepareCreate("test-get").addAlias(new Alias("alias-get")));
        client().prepareIndex("test-get", "type", "1").setSource("field","value").get();
        String indexGet = randomBoolean() ? "test-get" : "alias-get";

        MoreLikeThisRequest moreLikeThisRequest = new MoreLikeThisRequest(indexGet).type("type").id("1")
                .searchIndices(randomIndicesOrAliases());
        internalCluster().clientNodeClient().moreLikeThis(moreLikeThisRequest).actionGet();

        clearInterceptedActions();
        //get might end up being executed locally, only optionally over the transport
        assertSameIndicesOptionalRequests(new String[]{indexGet}, GetAction.NAME + "[s]");
        //query might end up being executed locally as well, only optionally over the transport
        assertSameIndicesOptionalRequests(moreLikeThisRequest.searchIndices(), SearchServiceTransportAction.QUERY_ACTION_NAME);
        //free context messages are not necessarily sent through the transport, but if they are, check their indices
        assertSameIndicesOptionalRequests(moreLikeThisRequest.searchIndices(), SearchServiceTransportAction.FETCH_ID_ACTION_NAME, SearchServiceTransportAction.FREE_CONTEXT_ACTION_NAME);
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.mlt.MoreLikeThisRequest

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.