Package org.elasticsearch.index.query
Class MoreLikeThisQueryBuilder
- java.lang.Object
-
- org.elasticsearch.index.query.AbstractQueryBuilder<MoreLikeThisQueryBuilder>
-
- org.elasticsearch.index.query.MoreLikeThisQueryBuilder
-
- All Implemented Interfaces:
NamedWriteable,Writeable,ToXContent,ToXContentObject,QueryBuilder,Rewriteable<QueryBuilder>
public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQueryBuilder>
A more like this query that finds documents that are "like" the provided set of document(s). The documents are provided as a set of strings and/or a list ofMoreLikeThisQueryBuilder.Item.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMoreLikeThisQueryBuilder.ItemA single item to be used for aMoreLikeThisQueryBuilder.-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Field Summary
Fields Modifier and Type Field Description static floatDEFAULT_BOOST_TERMSstatic booleanDEFAULT_FAIL_ON_UNSUPPORTED_FIELDSstatic booleanDEFAULT_INCLUDEstatic intDEFAULT_MAX_DOC_FREQstatic intDEFAULT_MAX_QUERY_TERMSstatic intDEFAULT_MAX_WORD_LENGTHstatic intDEFAULT_MIN_DOC_FREQstatic intDEFAULT_MIN_TERM_FREQstatic intDEFAULT_MIN_WORD_LENGTHstatic java.lang.StringDEFAULT_MINIMUM_SHOULD_MATCHstatic ParseFieldDOCstatic java.lang.StringNAME-
Fields inherited from class org.elasticsearch.index.query.AbstractQueryBuilder
boost, BOOST_FIELD, DEFAULT_BOOST, NAME_FIELD, queryName
-
Fields inherited from interface org.elasticsearch.index.query.Rewriteable
MAX_REWRITE_ROUNDS
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description MoreLikeThisQueryBuilder(java.lang.String[] fields, java.lang.String[] likeTexts, MoreLikeThisQueryBuilder.Item[] likeItems)Sets the field names that will be used when generating the 'More Like This' query.MoreLikeThisQueryBuilder(java.lang.String[] likeTexts, MoreLikeThisQueryBuilder.Item[] likeItems)Constructs a new more like this query which uses the "_all" field.MoreLikeThisQueryBuilder(StreamInput in)Read from a stream.
-
Method Summary
Modifier and Type Method Description java.lang.Stringanalyzer()MoreLikeThisQueryBuilderanalyzer(java.lang.String analyzer)The analyzer that will be used to analyze the text.floatboostTerms()MoreLikeThisQueryBuilderboostTerms(float boostTerms)Sets the boost factor to use when boosting terms.protected booleandoEquals(MoreLikeThisQueryBuilder other)Indicates whether some otherQueryBuilderobject of the same type is "equal to" this one.protected intdoHashCode()protected QueryBuilderdoRewrite(QueryRewriteContext queryRewriteContext)protected org.apache.lucene.search.QuerydoToQuery(QueryShardContext context)protected voiddoWriteTo(StreamOutput out)protected voiddoXContent(XContentBuilder builder, ToXContent.Params params)booleanfailOnUnsupportedField()MoreLikeThisQueryBuilderfailOnUnsupportedField(boolean fail)Whether to fail or return no result when this query is run against a field which is not supported such as binary/numeric fields.java.lang.String[]fields()static MoreLikeThisQueryBuilderfromXContent(XContentParser parser)java.lang.StringgetWriteableName()Returns the name of the writeable objectstatic MoreLikeThisQueryBuilder.Item[]ids(java.lang.String... ids)Deprecated.construct the items array externally and use it in the constructor / setterbooleaninclude()MoreLikeThisQueryBuilderinclude(boolean include)Whether to include the input documents.MoreLikeThisQueryBuilder.Item[]likeItems()java.lang.String[]likeTexts()intmaxDocFreq()MoreLikeThisQueryBuildermaxDocFreq(int maxDocFreq)Set the maximum frequency in which words may still appear.intmaxQueryTerms()MoreLikeThisQueryBuildermaxQueryTerms(int maxQueryTerms)Sets the maximum number of query terms that will be included in any generated query.intmaxWordLength()MoreLikeThisQueryBuildermaxWordLength(int maxWordLength)Sets the maximum word length above which words will be ignored.intminDocFreq()MoreLikeThisQueryBuilderminDocFreq(int minDocFreq)Sets the frequency at which words will be ignored which do not occur in at least this many docs.java.lang.StringminimumShouldMatch()MoreLikeThisQueryBuilderminimumShouldMatch(java.lang.String minimumShouldMatch)Number of terms that must match the generated query expressed in the common syntax for minimum should match.intminTermFreq()MoreLikeThisQueryBuilderminTermFreq(int minTermFreq)The frequency below which terms will be ignored in the source doc.intminWordLength()MoreLikeThisQueryBuilderminWordLength(int minWordLength)Sets the minimum word length below which words will be ignored.java.lang.String[]stopWords()MoreLikeThisQueryBuilderstopWords(java.lang.String... stopWords)Set the set of stopwords.MoreLikeThisQueryBuilderstopWords(java.util.List<java.lang.String> stopWords)MoreLikeThisQueryBuilderunlike(java.lang.String[] unlikeTexts)Sets the text from which the terms should not be selected from.MoreLikeThisQueryBuilderunlike(MoreLikeThisQueryBuilder.Item[] unlikeItems)Sets the documents from which the terms should not be selected from.MoreLikeThisQueryBuilder.Item[]unlikeItems()java.lang.String[]unlikeTexts()-
Methods inherited from class org.elasticsearch.index.query.AbstractQueryBuilder
addValidationError, boost, boost, checkNegativeBoost, declareStandardFields, equals, extractInnerHitBuilders, getName, hashCode, parseInnerQueryBuilder, printBoostAndQueryName, queryName, queryName, requireValue, rewrite, throwParsingExceptionOnMultipleFields, toFilter, toQuery, toString, toString, toXContent, writeTo
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
Field Detail
-
NAME
public static final java.lang.String NAME
- See Also:
- Constant Field Values
-
DEFAULT_MAX_QUERY_TERMS
public static final int DEFAULT_MAX_QUERY_TERMS
- See Also:
- Constant Field Values
-
DEFAULT_MIN_TERM_FREQ
public static final int DEFAULT_MIN_TERM_FREQ
- See Also:
- Constant Field Values
-
DEFAULT_MIN_DOC_FREQ
public static final int DEFAULT_MIN_DOC_FREQ
- See Also:
- Constant Field Values
-
DEFAULT_MAX_DOC_FREQ
public static final int DEFAULT_MAX_DOC_FREQ
- See Also:
- Constant Field Values
-
DEFAULT_MIN_WORD_LENGTH
public static final int DEFAULT_MIN_WORD_LENGTH
- See Also:
- Constant Field Values
-
DEFAULT_MAX_WORD_LENGTH
public static final int DEFAULT_MAX_WORD_LENGTH
- See Also:
- Constant Field Values
-
DEFAULT_MINIMUM_SHOULD_MATCH
public static final java.lang.String DEFAULT_MINIMUM_SHOULD_MATCH
- See Also:
- Constant Field Values
-
DEFAULT_BOOST_TERMS
public static final float DEFAULT_BOOST_TERMS
- See Also:
- Constant Field Values
-
DEFAULT_INCLUDE
public static final boolean DEFAULT_INCLUDE
- See Also:
- Constant Field Values
-
DEFAULT_FAIL_ON_UNSUPPORTED_FIELDS
public static final boolean DEFAULT_FAIL_ON_UNSUPPORTED_FIELDS
- See Also:
- Constant Field Values
-
DOC
public static final ParseField DOC
-
-
Constructor Detail
-
MoreLikeThisQueryBuilder
public MoreLikeThisQueryBuilder(java.lang.String[] likeTexts, MoreLikeThisQueryBuilder.Item[] likeItems)Constructs a new more like this query which uses the "_all" field.- Parameters:
likeTexts- the text to use when generating the 'More Like This' query.likeItems- the documents to use when generating the 'More Like This' query.
-
MoreLikeThisQueryBuilder
public MoreLikeThisQueryBuilder(@Nullable java.lang.String[] fields, @Nullable java.lang.String[] likeTexts, @Nullable MoreLikeThisQueryBuilder.Item[] likeItems)
Sets the field names that will be used when generating the 'More Like This' query.- Parameters:
fields- the field names that will be used when generating the 'More Like This' query.likeTexts- the text to use when generating the 'More Like This' query.likeItems- the documents to use when generating the 'More Like This' query.
-
MoreLikeThisQueryBuilder
public MoreLikeThisQueryBuilder(StreamInput in) throws java.io.IOException
Read from a stream.- Throws:
java.io.IOException
-
-
Method Detail
-
doWriteTo
protected void doWriteTo(StreamOutput out) throws java.io.IOException
- Specified by:
doWriteToin classAbstractQueryBuilder<MoreLikeThisQueryBuilder>- Throws:
java.io.IOException
-
fields
public java.lang.String[] fields()
-
likeTexts
public java.lang.String[] likeTexts()
-
likeItems
public MoreLikeThisQueryBuilder.Item[] likeItems()
-
unlike
public MoreLikeThisQueryBuilder unlike(java.lang.String[] unlikeTexts)
Sets the text from which the terms should not be selected from.
-
unlikeTexts
public java.lang.String[] unlikeTexts()
-
unlike
public MoreLikeThisQueryBuilder unlike(MoreLikeThisQueryBuilder.Item[] unlikeItems)
Sets the documents from which the terms should not be selected from.
-
unlikeItems
public MoreLikeThisQueryBuilder.Item[] unlikeItems()
-
maxQueryTerms
public MoreLikeThisQueryBuilder maxQueryTerms(int maxQueryTerms)
Sets the maximum number of query terms that will be included in any generated query. Defaults to25.
-
maxQueryTerms
public int maxQueryTerms()
-
minTermFreq
public MoreLikeThisQueryBuilder minTermFreq(int minTermFreq)
The frequency below which terms will be ignored in the source doc. The default frequency is2.
-
minTermFreq
public int minTermFreq()
-
minDocFreq
public MoreLikeThisQueryBuilder minDocFreq(int minDocFreq)
Sets the frequency at which words will be ignored which do not occur in at least this many docs. Defaults to5.
-
minDocFreq
public int minDocFreq()
-
maxDocFreq
public MoreLikeThisQueryBuilder maxDocFreq(int maxDocFreq)
Set the maximum frequency in which words may still appear. Words that appear in more than this many docs will be ignored. Defaults to unbounded.
-
maxDocFreq
public int maxDocFreq()
-
minWordLength
public MoreLikeThisQueryBuilder minWordLength(int minWordLength)
Sets the minimum word length below which words will be ignored. Defaults to0.
-
minWordLength
public int minWordLength()
-
maxWordLength
public MoreLikeThisQueryBuilder maxWordLength(int maxWordLength)
Sets the maximum word length above which words will be ignored. Defaults to unbounded (0).
-
maxWordLength
public int maxWordLength()
-
stopWords
public MoreLikeThisQueryBuilder stopWords(java.lang.String... stopWords)
Set the set of stopwords.Any word in this set is considered "uninteresting" and ignored. Even if your Analyzer allows stopwords, you might want to tell the MoreLikeThis code to ignore them, as for the purposes of document similarity it seems reasonable to assume that "a stop word is never interesting".
-
stopWords
public MoreLikeThisQueryBuilder stopWords(java.util.List<java.lang.String> stopWords)
-
stopWords
public java.lang.String[] stopWords()
-
analyzer
public MoreLikeThisQueryBuilder analyzer(java.lang.String analyzer)
The analyzer that will be used to analyze the text. Defaults to the analyzer associated with the field.
-
analyzer
public java.lang.String analyzer()
-
minimumShouldMatch
public MoreLikeThisQueryBuilder minimumShouldMatch(java.lang.String minimumShouldMatch)
Number of terms that must match the generated query expressed in the common syntax for minimum should match. Defaults to30%.
-
minimumShouldMatch
public java.lang.String minimumShouldMatch()
-
boostTerms
public MoreLikeThisQueryBuilder boostTerms(float boostTerms)
Sets the boost factor to use when boosting terms. Defaults to0(deactivated).
-
boostTerms
public float boostTerms()
-
include
public MoreLikeThisQueryBuilder include(boolean include)
Whether to include the input documents. Defaults tofalse
-
include
public boolean include()
-
failOnUnsupportedField
public MoreLikeThisQueryBuilder failOnUnsupportedField(boolean fail)
Whether to fail or return no result when this query is run against a field which is not supported such as binary/numeric fields.
-
failOnUnsupportedField
public boolean failOnUnsupportedField()
-
ids
@Deprecated public static MoreLikeThisQueryBuilder.Item[] ids(java.lang.String... ids)
Deprecated.construct the items array externally and use it in the constructor / setterConverts an array of String ids to and Item[].- Parameters:
ids- the ids to convert- Returns:
- the new items array
-
doXContent
protected void doXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
doXContentin classAbstractQueryBuilder<MoreLikeThisQueryBuilder>- Throws:
java.io.IOException
-
fromXContent
public static MoreLikeThisQueryBuilder fromXContent(XContentParser parser) throws java.io.IOException
- Throws:
java.io.IOException
-
getWriteableName
public java.lang.String getWriteableName()
Description copied from interface:NamedWriteableReturns the name of the writeable object
-
doToQuery
protected org.apache.lucene.search.Query doToQuery(QueryShardContext context) throws java.io.IOException
- Specified by:
doToQueryin classAbstractQueryBuilder<MoreLikeThisQueryBuilder>- Throws:
java.io.IOException
-
doHashCode
protected int doHashCode()
- Specified by:
doHashCodein classAbstractQueryBuilder<MoreLikeThisQueryBuilder>
-
doEquals
protected boolean doEquals(MoreLikeThisQueryBuilder other)
Description copied from class:AbstractQueryBuilderIndicates whether some otherQueryBuilderobject of the same type is "equal to" this one.- Specified by:
doEqualsin classAbstractQueryBuilder<MoreLikeThisQueryBuilder>
-
doRewrite
protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext)
- Overrides:
doRewritein classAbstractQueryBuilder<MoreLikeThisQueryBuilder>
-
-