ElasticSearch java API-use More like this to implement Content-based recommendation

Source: Internet
Author: User

ElasticSearch java API-use More like this to implement Content-based recommendation

ElasticSearch java API-use More like this to implement Content-based recommendation

Content-based recommendations generally give a document information, and then recommend the documents that meet the document. Lucene's api provides an interface for querying document similarity, called MoreLikeThis. Elasticsearch encapsulates this interface. Through the More like this query interface of Elasticsearch, we can easily implement Content-based recommendation.
First, let's look at the json example of a query request:

{ "more_like_this" : {"fields" : ["title", "content"],"like_text" : "text like this one"}}  

Fields is the field to be matched. If this parameter is left blank, the _ all field is used by default.

Like_text is the matched text.

In addition, you can add the following conditions to adjust the results.

Percent_terms_to_match: Percentage of the matching item (term). The default value is 0.3.

Min_term_freq: the number of times a word appears in a document. Words smaller than this value are ignored. The default value is 2.

Max_query_terms: Maximum number of words that can be queried in a query statement. The default value is 25.

Stop_words: Set the stop word. The Stop Word is ignored during matching.

Min_doc_freq: the minimum number of documents that contain a word. Words smaller than this value are ignored. The default value is unlimited.

Max_doc_freq: Maximum number of documents that a word can appear in. Words greater than this value are ignored. The default value is unlimited.

Min_word_len: Minimum word length. The default value is 0.

Max_word_len: Maximum length of words. The default value is unlimited.

Boost_terms: Set the word weight. The default value is 1.

Boost: Set the query weight. The default value is 1.

Analyzer: used word divider. By default, the analyzer specified by this field is used to describe how to call java APIs. There are three call methods, but they are essentially the same, however, it is encapsulated to varying degrees.

MoreLikeThisRequestBuilder mlt = new MoreLikeThisRequestBuilder (client, "indexName", "indexType", "id"); mlt. setField ("title"); // Matched Field SearchResponse response = client. moreLikeThis (mlt. request ()). actionGet ();

This type of query is similar to a document with a specific id. This interface is called directly from the client, which is special. Two other methods are used to construct a Query for Query.

MoreLikeThisQueryBuilder query = QueryBuilders. moreLikeThisQuery (); query. boost (1.0f). likeText ("test"). minTermFreq (10 );

The boost and likeText methods here completely correspond to the above parameters. In the following example, the field to be matched is passed as a parameter. The parameter is the same as that of MoreLikeThisQueryBuilder.

MoreLikeThisFieldQueryBuilder query = QueryBuilders. moreLikeThisFieldQuery ("test ");

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.