Module org.elasticsearch.server
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
,VersionedNamedWriteable
,Writeable
,QueryBuilder
,Rewriteable<QueryBuilder>
,ToXContent
,ToXContentObject
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 of
MoreLikeThisQueryBuilder.Item
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
A single item to be used for aMoreLikeThisQueryBuilder
.Nested classes/interfaces inherited from interface org.elasticsearch.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
FieldsModifier and TypeFieldDescriptionstatic final float
static final boolean
static final boolean
static final int
static final int
static final int
static final int
static final int
static final int
static final String
static final ParseField
static final String
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.xcontent.ToXContent
EMPTY_PARAMS
-
Constructor Summary
ConstructorsConstructorDescriptionMoreLikeThisQueryBuilder
(String[] fields, String[] likeTexts, MoreLikeThisQueryBuilder.Item[] likeItems) Sets the field names that will be used when generating the 'More Like This' query.MoreLikeThisQueryBuilder
(String[] likeTexts, MoreLikeThisQueryBuilder.Item[] likeItems) Constructs a new more like this query which uses the default search field.Read from a stream. -
Method Summary
Modifier and TypeMethodDescriptionanalyzer()
The analyzer that will be used to analyze the text.float
boostTerms
(float boostTerms) Sets the boost factor to use when boosting terms.protected boolean
doEquals
(MoreLikeThisQueryBuilder other) Indicates whether some otherQueryBuilder
object of the same type is "equal to" this one.protected int
protected QueryBuilder
doRewrite
(QueryRewriteContext queryRewriteContext) protected org.apache.lucene.search.Query
doToQuery
(SearchExecutionContext context) protected void
doWriteTo
(StreamOutput out) protected void
doXContent
(XContentBuilder builder, ToXContent.Params params) boolean
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.String[]
fields()
static MoreLikeThisQueryBuilder
fromXContent
(XContentParser parser) The minimal version of the recipient this object can be sent toReturns the name of the writeable objectboolean
include()
include
(boolean include) Whether to include the input documents.String[]
int
maxDocFreq
(int maxDocFreq) Set the maximum frequency in which words may still appear.int
maxQueryTerms
(int maxQueryTerms) Sets the maximum number of query terms that will be included in any generated query.int
maxWordLength
(int maxWordLength) Sets the maximum word length above which words will be ignored.int
minDocFreq
(int minDocFreq) Sets the frequency at which words will be ignored which do not occur in at least this many docs.minimumShouldMatch
(String minimumShouldMatch) Number of terms that must match the generated query expressed in the common syntax for minimum should match.int
minTermFreq
(int minTermFreq) The frequency below which terms will be ignored in the source doc.int
minWordLength
(int minWordLength) Sets the minimum word length below which words will be ignored.String[]
Set the set of stopwords.Sets the text from which the terms should not be selected from.unlike
(MoreLikeThisQueryBuilder.Item[] unlikeItems) Sets the documents from which the terms should not be selected from.String[]
Methods inherited from class org.elasticsearch.index.query.AbstractQueryBuilder
addValidationError, boost, boost, boostAndQueryNameToXContent, checkNegativeBoost, declareStandardFields, equals, extractInnerHitBuilders, getMaxNestedDepth, getName, hashCode, parseInnerQueryBuilder, parseTopLevelQuery, parseTopLevelQuery, printBoostAndQueryName, queryName, queryName, readQueries, requireValue, rewrite, setMaxNestedDepth, throwParsingExceptionOnMultipleFields, toQuery, toString, toXContent, writeQueries, writeTo
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.elasticsearch.xcontent.ToXContentObject
isFragment
-
Field Details
-
NAME
- See Also:
-
DEFAULT_MAX_QUERY_TERMS
public static final int DEFAULT_MAX_QUERY_TERMS- See Also:
-
DEFAULT_MIN_TERM_FREQ
public static final int DEFAULT_MIN_TERM_FREQ- See Also:
-
DEFAULT_MIN_DOC_FREQ
public static final int DEFAULT_MIN_DOC_FREQ- See Also:
-
DEFAULT_MAX_DOC_FREQ
public static final int DEFAULT_MAX_DOC_FREQ- See Also:
-
DEFAULT_MIN_WORD_LENGTH
public static final int DEFAULT_MIN_WORD_LENGTH- See Also:
-
DEFAULT_MAX_WORD_LENGTH
public static final int DEFAULT_MAX_WORD_LENGTH- See Also:
-
DEFAULT_MINIMUM_SHOULD_MATCH
- See Also:
-
DEFAULT_BOOST_TERMS
public static final float DEFAULT_BOOST_TERMS- See Also:
-
DEFAULT_INCLUDE
public static final boolean DEFAULT_INCLUDE- See Also:
-
DEFAULT_FAIL_ON_UNSUPPORTED_FIELDS
public static final boolean DEFAULT_FAIL_ON_UNSUPPORTED_FIELDS- See Also:
-
DOC
-
-
Constructor Details
-
MoreLikeThisQueryBuilder
Constructs a new more like this query which uses the default search 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 String[] fields, @Nullable 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
Read from a stream.- Throws:
IOException
-
-
Method Details
-
doWriteTo
- Specified by:
doWriteTo
in classAbstractQueryBuilder<MoreLikeThisQueryBuilder>
- Throws:
IOException
-
fields
-
likeTexts
-
likeItems
-
unlike
Sets the text from which the terms should not be selected from. -
unlikeTexts
-
unlike
Sets the documents from which the terms should not be selected from. -
unlikeItems
-
maxQueryTerms
Sets the maximum number of query terms that will be included in any generated query. Defaults to25
. -
maxQueryTerms
public int maxQueryTerms() -
minTermFreq
The frequency below which terms will be ignored in the source doc. The default frequency is2
. -
minTermFreq
public int minTermFreq() -
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
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
Sets the minimum word length below which words will be ignored. Defaults to0
. -
minWordLength
public int minWordLength() -
maxWordLength
Sets the maximum word length above which words will be ignored. Defaults to unbounded (0
). -
maxWordLength
public int maxWordLength() -
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
-
stopWords
-
analyzer
The analyzer that will be used to analyze the text. Defaults to the analyzer associated with the field. -
analyzer
-
minimumShouldMatch
Number of terms that must match the generated query expressed in the common syntax for minimum should match. Defaults to30%
. -
minimumShouldMatch
-
boostTerms
Sets the boost factor to use when boosting terms. Defaults to0
(deactivated). -
boostTerms
public float boostTerms() -
include
Whether to include the input documents. Defaults tofalse
-
include
public boolean include() -
failOnUnsupportedField
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() -
doXContent
- Specified by:
doXContent
in classAbstractQueryBuilder<MoreLikeThisQueryBuilder>
- Throws:
IOException
-
fromXContent
- Throws:
IOException
-
getWriteableName
Description copied from interface:VersionedNamedWriteable
Returns the name of the writeable object -
doToQuery
protected org.apache.lucene.search.Query doToQuery(SearchExecutionContext context) throws IOException - Specified by:
doToQuery
in classAbstractQueryBuilder<MoreLikeThisQueryBuilder>
- Throws:
IOException
-
doHashCode
protected int doHashCode()- Specified by:
doHashCode
in classAbstractQueryBuilder<MoreLikeThisQueryBuilder>
-
doEquals
Description copied from class:AbstractQueryBuilder
Indicates whether some otherQueryBuilder
object of the same type is "equal to" this one.- Specified by:
doEquals
in classAbstractQueryBuilder<MoreLikeThisQueryBuilder>
-
doRewrite
- Overrides:
doRewrite
in classAbstractQueryBuilder<MoreLikeThisQueryBuilder>
-
getMinimalSupportedVersion
Description copied from interface:VersionedNamedWriteable
The minimal version of the recipient this object can be sent to
-