MLT Field Query: remove it from master

The MLT field query is simply replaced by a MLT query set to specififc field.
To simplify code maintenance we should deprecate it in 1.4 and remove it in
2.0.

Closes #8238
This commit is contained in:
Alex Ksikes 2014-10-27 15:15:04 +01:00
parent bf1aed14db
commit 35f55608cc
11 changed files with 11 additions and 539 deletions

View File

@ -238,7 +238,6 @@ QueryBuilder qb = matchAllQuery();
See:
* {ref}/query-dsl-mlt-query.html[More Like This Query]
* {ref}/query-dsl-mlt-field-query.html[More Like This Field Query]
[source,java]
--------------------------------------------------
@ -253,20 +252,6 @@ QueryBuilder qb = moreLikeThisQuery("name.first", "name.last") <1>
<3> ignore threshold
<4> max num of Terms in generated queries
[source,java]
--------------------------------------------------
// mlt_field Query
QueryBuilder qb = moreLikeThisFieldQuery("name.first") <1>
.likeText("text like this one") <2>
.minTermFreq(1) <3>
.maxQueryTerms(12); <4>
--------------------------------------------------
<1> field
<2> text
<3> ignore threshold
<4> max num of Terms in generated queries
[[prefix]]
=== Prefix Query

View File

@ -14,3 +14,8 @@ to change this behavior
=== Partial fields
Partial fields were deprecated since 1.0.0beta1 in favor of <<search-request-source-filtering,source filtering>>.
=== More Like This Field
The More Like This Field query has been removed in favor of the <<query-dsl-mlt-query, More Like This Query>>
restrained set to a specific `field`.

View File

@ -44,8 +44,6 @@ include::queries/match-all-query.asciidoc[]
include::queries/mlt-query.asciidoc[]
include::queries/mlt-field-query.asciidoc[]
include::queries/nested-query.asciidoc[]
include::queries/prefix-query.asciidoc[]

View File

@ -1,74 +0,0 @@
[[query-dsl-mlt-field-query]]
=== More Like This Field Query
The `more_like_this_field` query is the same as the `more_like_this`
query, except it runs against a single field. It provides nicer query
DSL over the generic `more_like_this` query, and support typed fields
query (automatically wraps typed fields with type filter to match only
on the specific type).
[source,js]
--------------------------------------------------
{
"more_like_this_field" : {
"name.first" : {
"like_text" : "text like this one",
"min_term_freq" : 1,
"max_query_terms" : 12
}
}
}
--------------------------------------------------
`more_like_this_field` can be shortened to `mlt_field`.
The `more_like_this_field` top level parameters include:
[cols="<,<",options="header",]
|=======================================================================
|Parameter |Description
|`like_text` |The text to find documents like it, *required*.
|`minimum_should_match`| coming[1.5.0] From the generated query, the number of terms that
must match following the <<query-dsl-minimum-should-match,minimum should
syntax>>. (Defaults to `"30%"`).
|`percent_terms_to_match` | deprecated[1.5.0,Replaced by `minimum_should_match`]
From the generated query, the percentage of terms that must match (float value
between 0 and 1). Defaults to `0.3` (30 percent).
|`min_term_freq` |The frequency below which terms will be ignored in the
source doc. The default frequency is `2`.
|`max_query_terms` |The maximum number of query terms that will be
included in any generated query. Defaults to `25`.
|`stop_words` |An array of stop words. 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".
|`min_doc_freq` |The frequency at which words will be ignored which do
not occur in at least this many docs. Defaults to `5`.
|`max_doc_freq` |The maximum frequency in which words may still appear.
Words that appear in more than this many docs will be ignored. Defaults
to unbounded.
|`min_word_length` |The minimum word length below which words will be
ignored. Defaults to `0`. (Old name "min_word_len" is deprecated)
|`max_word_length` |The maximum word length above which words will be
ignored. Defaults to unbounded (`0`). (Old name "max_word_len" is deprecated)
|`boost_terms` |Sets the boost factor to use when boosting terms.
Defaults to deactivated (`0`). Any other value activates boosting with given
boost factor.
|`boost` |Sets the boost value of the query. Defaults to `1.0`.
|`analyzer` |The analyzer that will be used to analyze the text.
Defaults to the analyzer associated with the field.
|=======================================================================

View File

@ -46,7 +46,7 @@ import org.elasticsearch.index.get.GetField;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.mapper.internal.SourceFieldMapper;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MoreLikeThisFieldQueryBuilder;
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.threadpool.ThreadPool;
@ -321,14 +321,14 @@ public class TransportMoreLikeThisAction extends HandledTransportAction<MoreLike
}
private void addMoreLikeThis(MoreLikeThisRequest request, BoolQueryBuilder boolBuilder, String fieldName, String likeText, boolean failOnUnsupportedField) {
MoreLikeThisFieldQueryBuilder mlt = moreLikeThisFieldQuery(fieldName)
MoreLikeThisQueryBuilder mlt = moreLikeThisQuery(fieldName)
.likeText(likeText)
.minimumShouldMatch(request.minimumShouldMatch())
.boostTerms(request.boostTerms())
.minDocFreq(request.minDocFreq())
.maxDocFreq(request.maxDocFreq())
.minWordLength(request.minWordLength())
.maxWordLen(request.maxWordLength())
.maxWordLength(request.maxWordLength())
.minTermFreq(request.minTermFreq())
.maxQueryTerms(request.maxQueryTerms())
.stopWords(request.stopWords())

View File

@ -1,243 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.query;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
/**
* A more like this query that runs against a specific field.
*/
public class MoreLikeThisFieldQueryBuilder extends BaseQueryBuilder implements BoostableQueryBuilder<MoreLikeThisFieldQueryBuilder> {
private final String name;
private String likeText;
private String minimumShouldMatch = null;
private int minTermFreq = -1;
private int maxQueryTerms = -1;
private String[] stopWords = null;
private int minDocFreq = -1;
private int maxDocFreq = -1;
private int minWordLength = -1;
private int maxWordLength = -1;
private float boostTerms = -1;
private float boost = -1;
private String analyzer;
private Boolean failOnUnsupportedField;
private String queryName;
/**
* A more like this query that runs against a specific field.
*
* @param name The field name to run the query against
*/
public MoreLikeThisFieldQueryBuilder(String name) {
this.name = name;
}
/**
* The text to use in order to find documents that are "like" this.
*/
public MoreLikeThisFieldQueryBuilder likeText(String likeText) {
this.likeText = likeText;
return this;
}
/**
* Number of terms that must match the generated query expressed in the
* common syntax for minimum should match. Defaults to <tt>30%</tt>.
*
* @see org.elasticsearch.common.lucene.search.Queries#calculateMinShouldMatch(int, String)
*/
public MoreLikeThisFieldQueryBuilder minimumShouldMatch(String minimumShouldMatch) {
this.minimumShouldMatch = minimumShouldMatch;
return this;
}
/**
* The percentage of terms to match. Defaults to <tt>0.3</tt>.
*/
@Deprecated
public MoreLikeThisFieldQueryBuilder percentTermsToMatch(float percentTermsToMatch) {
return minimumShouldMatch(Math.round(percentTermsToMatch * 100) + "%");
}
/**
* The frequency below which terms will be ignored in the source doc. The default
* frequency is <tt>2</tt>.
*/
public MoreLikeThisFieldQueryBuilder minTermFreq(int minTermFreqy) {
this.minTermFreq = minTermFreqy;
return this;
}
/**
* Sets the maximum number of query terms that will be included in any generated query.
* Defaults to <tt>25</tt>.
*/
public MoreLikeThisFieldQueryBuilder maxQueryTerms(int maxQueryTerms) {
this.maxQueryTerms = maxQueryTerms;
return this;
}
/**
* Set the set of stopwords.
* <p/>
* <p>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".
*/
public MoreLikeThisFieldQueryBuilder stopWords(String... stopWords) {
this.stopWords = stopWords;
return this;
}
/**
* Sets the frequency at which words will be ignored which do not occur in at least this
* many docs. Defaults to <tt>5</tt>.
*/
public MoreLikeThisFieldQueryBuilder minDocFreq(int minDocFreq) {
this.minDocFreq = minDocFreq;
return this;
}
/**
* 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.
*/
public MoreLikeThisFieldQueryBuilder maxDocFreq(int maxDocFreq) {
this.maxDocFreq = maxDocFreq;
return this;
}
/**
* Sets the minimum word length below which words will be ignored. Defaults
* to <tt>0</tt>.
*/
public MoreLikeThisFieldQueryBuilder minWordLength(int minWordLength) {
this.minWordLength = minWordLength;
return this;
}
/**
* Sets the maximum word length above which words will be ignored. Defaults to
* unbounded (<tt>0</tt>).
*/
public MoreLikeThisFieldQueryBuilder maxWordLen(int maxWordLen) {
this.maxWordLength = maxWordLen;
return this;
}
/**
* Sets the boost factor to use when boosting terms. Defaults to <tt>1</tt>.
*/
public MoreLikeThisFieldQueryBuilder boostTerms(float boostTerms) {
this.boostTerms = boostTerms;
return this;
}
/**
* The analyzer that will be used to analyze the text. Defaults to the analyzer associated with the fied.
*/
public MoreLikeThisFieldQueryBuilder analyzer(String analyzer) {
this.analyzer = analyzer;
return this;
}
public MoreLikeThisFieldQueryBuilder boost(float boost) {
this.boost = boost;
return this;
}
/**
* Whether to fail or return no result when this query is run against a field which is not supported such as binary/numeric fields.
*/
public MoreLikeThisFieldQueryBuilder failOnUnsupportedField(boolean fail) {
failOnUnsupportedField = fail;
return this;
}
/**
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
*/
public MoreLikeThisFieldQueryBuilder queryName(String queryName) {
this.queryName = queryName;
return this;
}
@Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(MoreLikeThisFieldQueryParser.NAME);
builder.startObject(name);
if (likeText == null) {
throw new ElasticsearchIllegalArgumentException("moreLikeThisField requires '"+
MoreLikeThisQueryParser.Fields.LIKE_TEXT.getPreferredName() +"' to be provided");
}
builder.field(MoreLikeThisQueryParser.Fields.LIKE_TEXT.getPreferredName(), likeText);
if (minimumShouldMatch != null) {
builder.field(MoreLikeThisQueryParser.Fields.MINIMUM_SHOULD_MATCH.getPreferredName(), minimumShouldMatch);
}
if (minTermFreq != -1) {
builder.field(MoreLikeThisQueryParser.Fields.MIN_TERM_FREQ.getPreferredName(), minTermFreq);
}
if (maxQueryTerms != -1) {
builder.field(MoreLikeThisQueryParser.Fields.MAX_QUERY_TERMS.getPreferredName(), maxQueryTerms);
}
if (stopWords != null && stopWords.length > 0) {
builder.startArray(MoreLikeThisQueryParser.Fields.STOP_WORDS.getPreferredName());
for (String stopWord : stopWords) {
builder.value(stopWord);
}
builder.endArray();
}
if (minDocFreq != -1) {
builder.field(MoreLikeThisQueryParser.Fields.MIN_DOC_FREQ.getPreferredName(), minDocFreq);
}
if (maxDocFreq != -1) {
builder.field(MoreLikeThisQueryParser.Fields.MAX_DOC_FREQ.getPreferredName(), maxDocFreq);
}
if (minWordLength != -1) {
builder.field(MoreLikeThisQueryParser.Fields.MIN_WORD_LENGTH.getPreferredName(), minWordLength);
}
if (maxWordLength != -1) {
builder.field(MoreLikeThisQueryParser.Fields.MAX_WORD_LENGTH.getPreferredName(), maxWordLength);
}
if (boostTerms != -1) {
builder.field(MoreLikeThisQueryParser.Fields.BOOST_TERMS.getPreferredName(), boostTerms);
}
if (boost != -1) {
builder.field("boost", boost);
}
if (analyzer != null) {
builder.field("analyzer", analyzer);
}
if (failOnUnsupportedField != null) {
builder.field(MoreLikeThisQueryParser.Fields.FAIL_ON_UNSUPPORTED_FIELD.getPreferredName(), failOnUnsupportedField);
}
if (queryName != null) {
builder.field("_name", queryName);
}
builder.endObject();
builder.endObject();
}
}

View File

@ -1,163 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.query;
import com.google.common.collect.Sets;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.search.Query;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.search.MoreLikeThisQuery;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.analysis.Analysis;
import org.elasticsearch.index.mapper.MapperService;
import java.io.IOException;
import java.util.Set;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
/**
*
*/
public class MoreLikeThisFieldQueryParser implements QueryParser {
public static final String NAME = "mlt_field";
@Inject
public MoreLikeThisFieldQueryParser() {
}
@Override
public String[] names() {
return new String[]{NAME, "more_like_this_field", Strings.toCamelCase(NAME), "moreLikeThisField"};
}
@Override
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
XContentParser parser = parseContext.parser();
XContentParser.Token token = parser.nextToken();
assert token == XContentParser.Token.FIELD_NAME;
String fieldName = parser.currentName();
// now, we move after the field name, which starts the object
token = parser.nextToken();
assert token == XContentParser.Token.START_OBJECT;
MoreLikeThisQuery mltQuery = new MoreLikeThisQuery();
mltQuery.setSimilarity(parseContext.searchSimilarity());
Analyzer analyzer = null;
boolean failOnUnsupportedField = true;
String queryName = null;
String currentFieldName = null;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if (MoreLikeThisQueryParser.Fields.LIKE_TEXT.match(currentFieldName,parseContext.parseFlags()) ) {
mltQuery.setLikeText(parser.text());
} else if (MoreLikeThisQueryParser.Fields.MIN_TERM_FREQ.match(currentFieldName,parseContext.parseFlags()) ) {
mltQuery.setMinTermFrequency(parser.intValue());
} else if (MoreLikeThisQueryParser.Fields.MAX_QUERY_TERMS.match(currentFieldName,parseContext.parseFlags())) {
mltQuery.setMaxQueryTerms(parser.intValue());
} else if (MoreLikeThisQueryParser.Fields.MIN_DOC_FREQ.match(currentFieldName,parseContext.parseFlags())) {
mltQuery.setMinDocFreq(parser.intValue());
} else if (MoreLikeThisQueryParser.Fields.MAX_DOC_FREQ.match(currentFieldName,parseContext.parseFlags())) {
mltQuery.setMaxDocFreq(parser.intValue());
} else if (MoreLikeThisQueryParser.Fields.MIN_WORD_LENGTH.match(currentFieldName,parseContext.parseFlags())) {
mltQuery.setMinWordLen(parser.intValue());
} else if (MoreLikeThisQueryParser.Fields.MAX_WORD_LENGTH.match(currentFieldName,parseContext.parseFlags())) {
mltQuery.setMaxWordLen(parser.intValue());
} else if (MoreLikeThisQueryParser.Fields.BOOST_TERMS.match(currentFieldName,parseContext.parseFlags())) {
float boostFactor = parser.floatValue();
if (boostFactor != 0) {
mltQuery.setBoostTerms(true);
mltQuery.setBoostTermsFactor(boostFactor);
}
} else if (MoreLikeThisQueryParser.Fields.MINIMUM_SHOULD_MATCH.match(currentFieldName,parseContext.parseFlags())) {
mltQuery.setMinimumShouldMatch(parser.text());
} else if (MoreLikeThisQueryParser.Fields.PERCENT_TERMS_TO_MATCH.match(currentFieldName,parseContext.parseFlags())) {
mltQuery.setMinimumShouldMatch(Math.round(parser.floatValue() * 100) + "%");
} else if ("analyzer".equals(currentFieldName)) {
analyzer = parseContext.analysisService().analyzer(parser.text());
} else if ("boost".equals(currentFieldName)) {
mltQuery.setBoost(parser.floatValue());
} else if (MoreLikeThisQueryParser.Fields.FAIL_ON_UNSUPPORTED_FIELD.match(currentFieldName,parseContext.parseFlags())) {
failOnUnsupportedField = parser.booleanValue();
} else if ("_name".equals(currentFieldName)) {
queryName = parser.text();
} else {
throw new QueryParsingException(parseContext.index(), "[mlt_field] query does not support [" + currentFieldName + "]");
}
} else if (token == XContentParser.Token.START_ARRAY) {
if (MoreLikeThisQueryParser.Fields.STOP_WORDS.match(currentFieldName,parseContext.parseFlags())) {
Set<String> stopWords = Sets.newHashSet();
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
stopWords.add(parser.text());
}
mltQuery.setStopWords(stopWords);
} else {
throw new QueryParsingException(parseContext.index(), "[mlt_field] query does not support [" + currentFieldName + "]");
}
}
}
if (mltQuery.getLikeText() == null) {
throw new QueryParsingException(parseContext.index(), "more_like_this_field requires 'like_text' to be specified");
}
// move to the next end object, to close the field name
token = parser.nextToken();
assert token == XContentParser.Token.END_OBJECT;
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers != null) {
if (smartNameFieldMappers.hasMapper()) {
fieldName = smartNameFieldMappers.mapper().names().indexName();
}
if (analyzer == null) {
analyzer = smartNameFieldMappers.searchAnalyzer();
}
}
if (analyzer == null) {
analyzer = parseContext.mapperService().searchAnalyzer();
}
if (!Analysis.generatesCharacterTokenStream(analyzer, fieldName)) {
if (failOnUnsupportedField) {
throw new ElasticsearchIllegalArgumentException("more_like_this_field doesn't support binary/numeric fields: [" + fieldName + "]");
} else {
return null;
}
}
mltQuery.setAnalyzer(analyzer);
mltQuery.setMoreLikeFields(new String[]{fieldName});
Query query = wrapSmartNameQuery(mltQuery, smartNameFieldMappers, parseContext);
if (queryName != null) {
parseContext.addNamedQuery(queryName, query);
}
return query;
}
}

View File

@ -516,15 +516,6 @@ public abstract class QueryBuilders {
return new FuzzyLikeThisFieldQueryBuilder(name);
}
/**
* A more like this query that runs against a specific field.
*
* @param name The field name
*/
public static MoreLikeThisFieldQueryBuilder moreLikeThisFieldQuery(String name) {
return new MoreLikeThisFieldQueryBuilder(name);
}
/**
* Constructs a new scoring child query, with the child type and the query to run on the child documents. The
* results of this query are the parent docs that those child docs matched.

View File

@ -94,7 +94,6 @@ public class IndicesQueriesModule extends AbstractModule {
qpBinders.addBinding().to(SpanNearQueryParser.class).asEagerSingleton();
qpBinders.addBinding().to(SpanOrQueryParser.class).asEagerSingleton();
qpBinders.addBinding().to(MoreLikeThisQueryParser.class).asEagerSingleton();
qpBinders.addBinding().to(MoreLikeThisFieldQueryParser.class).asEagerSingleton();
qpBinders.addBinding().to(FuzzyLikeThisQueryParser.class).asEagerSingleton();
qpBinders.addBinding().to(FuzzyLikeThisFieldQueryParser.class).asEagerSingleton();
qpBinders.addBinding().to(WrapperQueryParser.class).asEagerSingleton();

View File

@ -1817,31 +1817,6 @@ public class SimpleIndexQueryParserTests extends ElasticsearchSingleNodeTest {
// FuzzyLikeThisQuery fuzzyLikeThisQuery = (FuzzyLikeThisQuery) parsedQuery;
}
@Test
public void testMoreLikeThisFieldBuilder() throws Exception {
IndexQueryParserService queryParser = queryParser();
Query parsedQuery = queryParser.parse(moreLikeThisFieldQuery("name.first").likeText("something").minTermFreq(1).maxQueryTerms(12)).query();
assertThat(parsedQuery, instanceOf(MoreLikeThisQuery.class));
MoreLikeThisQuery mltQuery = (MoreLikeThisQuery) parsedQuery;
assertThat(mltQuery.getMoreLikeFields()[0], equalTo("name.first"));
assertThat(mltQuery.getLikeText(), equalTo("something"));
assertThat(mltQuery.getMinTermFrequency(), equalTo(1));
assertThat(mltQuery.getMaxQueryTerms(), equalTo(12));
}
@Test
public void testMoreLikeThisField() throws Exception {
IndexQueryParserService queryParser = queryParser();
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/mltField.json");
Query parsedQuery = queryParser.parse(query).query();
assertThat(parsedQuery, instanceOf(MoreLikeThisQuery.class));
MoreLikeThisQuery mltQuery = (MoreLikeThisQuery) parsedQuery;
assertThat(mltQuery.getMoreLikeFields()[0], equalTo("name.first"));
assertThat(mltQuery.getLikeText(), equalTo("something"));
assertThat(mltQuery.getMinTermFrequency(), equalTo(1));
assertThat(mltQuery.getMaxQueryTerms(), equalTo(12));
}
@Test
public void testGeoDistanceFilterNamed() throws IOException {
IndexQueryParserService queryParser = queryParser();

View File

@ -50,7 +50,6 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.FilterBuilders.termFilter;
import static org.elasticsearch.index.query.QueryBuilders.moreLikeThisFieldQuery;
import static org.elasticsearch.index.query.QueryBuilders.moreLikeThisQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
import static org.hamcrest.Matchers.equalTo;
@ -258,14 +257,14 @@ public class MoreLikeThisActionTests extends ElasticsearchIntegrationTest {
assertHitCount(searchResponse, 2l);
// mlt field query on a numeric field -> failure by default
assertThrows(client().prepareSearch().setQuery(moreLikeThisFieldQuery("int_value").likeText("42").minTermFreq(1).minDocFreq(1)), SearchPhaseExecutionException.class);
assertThrows(client().prepareSearch().setQuery(moreLikeThisQuery("int_value").likeText("42").minTermFreq(1).minDocFreq(1)), SearchPhaseExecutionException.class);
// mlt field query on a numeric field -> failure by command
assertThrows(client().prepareSearch().setQuery(moreLikeThisFieldQuery("int_value").likeText("42").minTermFreq(1).minDocFreq(1).failOnUnsupportedField(true)),
assertThrows(client().prepareSearch().setQuery(moreLikeThisQuery("int_value").likeText("42").minTermFreq(1).minDocFreq(1).failOnUnsupportedField(true)),
SearchPhaseExecutionException.class);
// mlt field query on a numeric field but fail_on_unsupported_field set to false
searchResponse = client().prepareSearch().setQuery(moreLikeThisFieldQuery("int_value").likeText("42").minTermFreq(1).minDocFreq(1).failOnUnsupportedField(false)).execute().actionGet();
searchResponse = client().prepareSearch().setQuery(moreLikeThisQuery("int_value").likeText("42").minTermFreq(1).minDocFreq(1).failOnUnsupportedField(false)).execute().actionGet();
assertHitCount(searchResponse, 0l);
}