Remove deprecated type and slop field in MatchQueryBuilder (#26720)
The `type` field has been deprecated in 5.0 and can be removed. It has been replaced by using the MatchPhraseQueryBuilder or the MatchPhrasePrefixQueryBuilder. The `slop` field has also been deprecated and can be removed, the phrase and phrase prefix query builders still provide this parameter.
This commit is contained in:
parent
5f407062ad
commit
22e200e79a
|
@ -35,7 +35,6 @@ import org.elasticsearch.index.search.MatchQuery;
|
|||
import org.elasticsearch.index.search.MatchQuery.ZeroTermsQuery;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
@ -43,7 +42,6 @@ import java.util.Objects;
|
|||
* result of the analysis.
|
||||
*/
|
||||
public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
||||
public static final ParseField SLOP_FIELD = new ParseField("slop", "phrase_slop").withAllDeprecated("match_phrase query");
|
||||
public static final ParseField ZERO_TERMS_QUERY_FIELD = new ParseField("zero_terms_query");
|
||||
public static final ParseField CUTOFF_FREQUENCY_FIELD = new ParseField("cutoff_frequency");
|
||||
public static final ParseField LENIENT_FIELD = new ParseField("lenient");
|
||||
|
@ -54,7 +52,6 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
public static final ParseField MAX_EXPANSIONS_FIELD = new ParseField("max_expansions");
|
||||
public static final ParseField PREFIX_LENGTH_FIELD = new ParseField("prefix_length");
|
||||
public static final ParseField ANALYZER_FIELD = new ParseField("analyzer");
|
||||
public static final ParseField TYPE_FIELD = new ParseField("type").withAllDeprecated("match_phrase and match_phrase_prefix query");
|
||||
public static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
public static final ParseField GENERATE_SYNONYMS_PHRASE_QUERY = new ParseField("auto_generate_synonyms_phrase_query");
|
||||
|
||||
|
@ -64,24 +61,14 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
/** The default mode terms are combined in a match query */
|
||||
public static final Operator DEFAULT_OPERATOR = Operator.OR;
|
||||
|
||||
/** The default mode match query type */
|
||||
@Deprecated
|
||||
public static final MatchQuery.Type DEFAULT_TYPE = MatchQuery.Type.BOOLEAN;
|
||||
|
||||
private final String fieldName;
|
||||
|
||||
private final Object value;
|
||||
|
||||
@Deprecated
|
||||
private MatchQuery.Type type = DEFAULT_TYPE;
|
||||
|
||||
private Operator operator = DEFAULT_OPERATOR;
|
||||
|
||||
private String analyzer;
|
||||
|
||||
@Deprecated
|
||||
private int slop = MatchQuery.DEFAULT_PHRASE_SLOP;
|
||||
|
||||
private Fuzziness fuzziness = null;
|
||||
|
||||
private int prefixLength = FuzzyQuery.defaultPrefixLength;
|
||||
|
@ -123,9 +110,15 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
super(in);
|
||||
fieldName = in.readString();
|
||||
value = in.readGenericValue();
|
||||
type = MatchQuery.Type.readFromStream(in);
|
||||
// TODO lower this version once this has been backported to 6.0.0
|
||||
if (in.getVersion().before(Version.V_7_0_0_alpha1)) {
|
||||
MatchQuery.Type.readFromStream(in); // deprecated type
|
||||
}
|
||||
operator = Operator.readFromStream(in);
|
||||
slop = in.readVInt();
|
||||
// TODO lower this version once this has been backported to 6.0.0
|
||||
if (in.getVersion().before(Version.V_7_0_0_alpha1)) {
|
||||
in.readVInt(); // deprecated slop
|
||||
}
|
||||
prefixLength = in.readVInt();
|
||||
maxExpansions = in.readVInt();
|
||||
fuzzyTranspositions = in.readBoolean();
|
||||
|
@ -146,9 +139,15 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeGenericValue(value);
|
||||
type.writeTo(out);
|
||||
// TODO lower this version once this has been backported to 6.0.0
|
||||
if (out.getVersion().before(Version.V_7_0_0_alpha1)) {
|
||||
MatchQuery.Type.BOOLEAN.writeTo(out); // deprecated type
|
||||
}
|
||||
operator.writeTo(out);
|
||||
out.writeVInt(slop);
|
||||
// TODO lower this version once this has been backported to 6.0.0
|
||||
if (out.getVersion().before(Version.V_7_0_0_alpha1)) {
|
||||
out.writeVInt(MatchQuery.DEFAULT_PHRASE_SLOP); // deprecated slop
|
||||
}
|
||||
out.writeVInt(prefixLength);
|
||||
out.writeVInt(maxExpansions);
|
||||
out.writeBoolean(fuzzyTranspositions);
|
||||
|
@ -175,34 +174,6 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of the text query.
|
||||
*
|
||||
* @deprecated Use {@link MatchPhraseQueryBuilder} for <code>phrase</code>
|
||||
* queries and {@link MatchPhrasePrefixQueryBuilder} for
|
||||
* <code>phrase_prefix</code> queries
|
||||
*/
|
||||
@Deprecated
|
||||
public MatchQueryBuilder type(MatchQuery.Type type) {
|
||||
if (type == null) {
|
||||
throw new IllegalArgumentException("[" + NAME + "] requires type to be non-null");
|
||||
}
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of the query.
|
||||
*
|
||||
* @deprecated Use {@link MatchPhraseQueryBuilder} for <code>phrase</code>
|
||||
* queries and {@link MatchPhrasePrefixQueryBuilder} for
|
||||
* <code>phrase_prefix</code> queries
|
||||
*/
|
||||
@Deprecated
|
||||
public MatchQuery.Type type() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/** Sets the operator to use when using a boolean query. Defaults to <tt>OR</tt>. */
|
||||
public MatchQueryBuilder operator(Operator operator) {
|
||||
if (operator == null) {
|
||||
|
@ -231,30 +202,6 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
return this.analyzer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a slop factor for phrase queries
|
||||
*
|
||||
* @deprecated for phrase queries use {@link MatchPhraseQueryBuilder}
|
||||
*/
|
||||
@Deprecated
|
||||
public MatchQueryBuilder slop(int slop) {
|
||||
if (slop < 0 ) {
|
||||
throw new IllegalArgumentException("No negative slop allowed.");
|
||||
}
|
||||
this.slop = slop;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the slop factor for phrase queries.
|
||||
*
|
||||
* @deprecated for phrase queries use {@link MatchPhraseQueryBuilder}
|
||||
*/
|
||||
@Deprecated
|
||||
public int slop() {
|
||||
return this.slop;
|
||||
}
|
||||
|
||||
/** Sets the fuzziness used when evaluated to a fuzzy query type. Defaults to "AUTO". */
|
||||
public MatchQueryBuilder fuzziness(Object fuzziness) {
|
||||
this.fuzziness = Fuzziness.build(fuzziness);
|
||||
|
@ -425,18 +372,10 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
builder.startObject(fieldName);
|
||||
|
||||
builder.field(QUERY_FIELD.getPreferredName(), value);
|
||||
// this is deprecated so only output the value if its not the default value (for bwc)
|
||||
if (type != MatchQuery.Type.BOOLEAN) {
|
||||
builder.field(TYPE_FIELD.getPreferredName(), type.toString().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
builder.field(OPERATOR_FIELD.getPreferredName(), operator.toString());
|
||||
if (analyzer != null) {
|
||||
builder.field(ANALYZER_FIELD.getPreferredName(), analyzer);
|
||||
}
|
||||
// this is deprecated so only output the value if its not the default value (for bwc)
|
||||
if (slop != MatchQuery.DEFAULT_PHRASE_SLOP) {
|
||||
builder.field(SLOP_FIELD.getPreferredName(), slop);
|
||||
}
|
||||
if (fuzziness != null) {
|
||||
fuzziness.toXContent(builder, params);
|
||||
}
|
||||
|
@ -473,7 +412,6 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
if (analyzer != null) {
|
||||
matchQuery.setAnalyzer(analyzer);
|
||||
}
|
||||
matchQuery.setPhraseSlop(slop);
|
||||
matchQuery.setFuzziness(fuzziness);
|
||||
matchQuery.setFuzzyPrefixLength(prefixLength);
|
||||
matchQuery.setMaxExpansions(maxExpansions);
|
||||
|
@ -484,7 +422,7 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
matchQuery.setZeroTermsQuery(zeroTermsQuery);
|
||||
matchQuery.setAutoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery);
|
||||
|
||||
Query query = matchQuery.parse(type, fieldName, value);
|
||||
Query query = matchQuery.parse(MatchQuery.Type.BOOLEAN, fieldName, value);
|
||||
return Queries.maybeApplyMinimumShouldMatch(query, minimumShouldMatch);
|
||||
}
|
||||
|
||||
|
@ -492,10 +430,8 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
protected boolean doEquals(MatchQueryBuilder other) {
|
||||
return Objects.equals(fieldName, other.fieldName) &&
|
||||
Objects.equals(value, other.value) &&
|
||||
Objects.equals(type, other.type) &&
|
||||
Objects.equals(operator, other.operator) &&
|
||||
Objects.equals(analyzer, other.analyzer) &&
|
||||
Objects.equals(slop, other.slop) &&
|
||||
Objects.equals(fuzziness, other.fuzziness) &&
|
||||
Objects.equals(prefixLength, other.prefixLength) &&
|
||||
Objects.equals(maxExpansions, other.maxExpansions) &&
|
||||
|
@ -510,7 +446,7 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(fieldName, value, type, operator, analyzer, slop,
|
||||
return Objects.hash(fieldName, value, operator, analyzer,
|
||||
fuzziness, prefixLength, maxExpansions, minimumShouldMatch,
|
||||
fuzzyRewrite, lenient, fuzzyTranspositions, zeroTermsQuery, cutoffFrequency, autoGenerateSynonymsPhraseQuery);
|
||||
}
|
||||
|
@ -522,13 +458,11 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
|
||||
public static MatchQueryBuilder fromXContent(XContentParser parser) throws IOException {
|
||||
String fieldName = null;
|
||||
MatchQuery.Type type = MatchQuery.Type.BOOLEAN;
|
||||
Object value = null;
|
||||
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||
String minimumShouldMatch = null;
|
||||
String analyzer = null;
|
||||
Operator operator = MatchQueryBuilder.DEFAULT_OPERATOR;
|
||||
int slop = MatchQuery.DEFAULT_PHRASE_SLOP;
|
||||
Fuzziness fuzziness = null;
|
||||
int prefixLength = FuzzyQuery.defaultPrefixLength;
|
||||
int maxExpansion = FuzzyQuery.defaultMaxExpansions;
|
||||
|
@ -553,23 +487,10 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
} else if (token.isValue()) {
|
||||
if (QUERY_FIELD.match(currentFieldName)) {
|
||||
value = parser.objectText();
|
||||
} else if (TYPE_FIELD.match(currentFieldName)) {
|
||||
String tStr = parser.text();
|
||||
if ("boolean".equals(tStr)) {
|
||||
type = MatchQuery.Type.BOOLEAN;
|
||||
} else if ("phrase".equals(tStr)) {
|
||||
type = MatchQuery.Type.PHRASE;
|
||||
} else if ("phrase_prefix".equals(tStr) || ("phrasePrefix".equals(tStr))) {
|
||||
type = MatchQuery.Type.PHRASE_PREFIX;
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + NAME + "] query does not support type " + tStr);
|
||||
}
|
||||
} else if (ANALYZER_FIELD.match(currentFieldName)) {
|
||||
analyzer = parser.text();
|
||||
} else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
|
||||
boost = parser.floatValue();
|
||||
} else if (SLOP_FIELD.match(currentFieldName)) {
|
||||
slop = parser.intValue();
|
||||
} else if (Fuzziness.FIELD.match(currentFieldName)) {
|
||||
fuzziness = Fuzziness.parse(parser);
|
||||
} else if (PREFIX_LENGTH_FIELD.match(currentFieldName)) {
|
||||
|
@ -624,9 +545,7 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
|
||||
MatchQueryBuilder matchQuery = new MatchQueryBuilder(fieldName, value);
|
||||
matchQuery.operator(operator);
|
||||
matchQuery.type(type);
|
||||
matchQuery.analyzer(analyzer);
|
||||
matchQuery.slop(slop);
|
||||
matchQuery.minimumShouldMatch(minimumShouldMatch);
|
||||
if (fuzziness != null) {
|
||||
matchQuery.fuzziness(fuzziness);
|
||||
|
|
|
@ -24,10 +24,8 @@ import org.apache.lucene.search.BooleanClause;
|
|||
import org.apache.lucene.search.BooleanQuery;
|
||||
import org.apache.lucene.search.BoostQuery;
|
||||
import org.apache.lucene.search.FuzzyQuery;
|
||||
import org.apache.lucene.search.IndexOrDocValuesQuery;
|
||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.search.MatchNoDocsQuery;
|
||||
import org.apache.lucene.search.PhraseQuery;
|
||||
import org.apache.lucene.search.PointRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
|
@ -148,23 +146,6 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
|
|||
return;
|
||||
}
|
||||
|
||||
switch (queryBuilder.type()) {
|
||||
case BOOLEAN:
|
||||
assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(ExtendedCommonTermsQuery.class))
|
||||
.or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class)).or(instanceOf(MatchNoDocsQuery.class))
|
||||
.or(instanceOf(PointRangeQuery.class)).or(instanceOf(IndexOrDocValuesQuery.class)));
|
||||
break;
|
||||
case PHRASE:
|
||||
assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(PhraseQuery.class))
|
||||
.or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class))
|
||||
.or(instanceOf(PointRangeQuery.class)).or(instanceOf(IndexOrDocValuesQuery.class)));
|
||||
break;
|
||||
case PHRASE_PREFIX:
|
||||
assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(MultiPhrasePrefixQuery.class))
|
||||
.or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class))
|
||||
.or(instanceOf(PointRangeQuery.class)).or(instanceOf(IndexOrDocValuesQuery.class)));
|
||||
break;
|
||||
}
|
||||
QueryShardContext context = searchContext.getQueryShardContext();
|
||||
MappedFieldType fieldType = context.fieldMapper(queryBuilder.fieldName());
|
||||
if (query instanceof TermQuery && fieldType != null) {
|
||||
|
@ -250,11 +231,6 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
|
|||
assertEquals("[match] requires operator to be non-null", e.getMessage());
|
||||
}
|
||||
|
||||
{
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> matchQuery.type(null));
|
||||
assertEquals("[match] requires type to be non-null", e.getMessage());
|
||||
}
|
||||
|
||||
{
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> matchQuery.zeroTermsQuery(null));
|
||||
assertEquals("[match] requires zeroTermsQuery to be non-null", e.getMessage());
|
||||
|
@ -290,69 +266,6 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
|
|||
assertEquals(json, Operator.AND, qb.operator());
|
||||
}
|
||||
|
||||
public void testLegacyMatchPhrasePrefixQuery() throws IOException {
|
||||
MatchQueryBuilder expectedQB = new MatchQueryBuilder("message", "to be or not to be");
|
||||
expectedQB.type(Type.PHRASE_PREFIX);
|
||||
expectedQB.slop(2);
|
||||
expectedQB.maxExpansions(30);
|
||||
String json = "{\n" +
|
||||
" \"match\" : {\n" +
|
||||
" \"message\" : {\n" +
|
||||
" \"query\" : \"to be or not to be\",\n" +
|
||||
" \"type\" : \"phrase_prefix\",\n" +
|
||||
" \"operator\" : \"OR\",\n" +
|
||||
" \"slop\" : 2,\n" +
|
||||
" \"prefix_length\" : 0,\n" +
|
||||
" \"max_expansions\" : 30,\n" +
|
||||
" \"fuzzy_transpositions\" : true,\n" +
|
||||
" \"lenient\" : false,\n" +
|
||||
" \"zero_terms_query\" : \"NONE\",\n" +
|
||||
" \"auto_generate_synonyms_phrase_query\" : true,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
MatchQueryBuilder qb = (MatchQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, qb);
|
||||
|
||||
assertEquals(json, expectedQB, qb);
|
||||
|
||||
assertSerialization(qb);
|
||||
|
||||
assertWarnings("Deprecated field [type] used, replaced by [match_phrase and match_phrase_prefix query]",
|
||||
"Deprecated field [slop] used, replaced by [match_phrase query]");
|
||||
}
|
||||
|
||||
public void testLegacyMatchPhraseQuery() throws IOException {
|
||||
MatchQueryBuilder expectedQB = new MatchQueryBuilder("message", "to be or not to be");
|
||||
expectedQB.type(Type.PHRASE);
|
||||
expectedQB.slop(2);
|
||||
String json = "{\n" +
|
||||
" \"match\" : {\n" +
|
||||
" \"message\" : {\n" +
|
||||
" \"query\" : \"to be or not to be\",\n" +
|
||||
" \"type\" : \"phrase\",\n" +
|
||||
" \"operator\" : \"OR\",\n" +
|
||||
" \"slop\" : 2,\n" +
|
||||
" \"prefix_length\" : 0,\n" +
|
||||
" \"max_expansions\" : 50,\n" +
|
||||
" \"fuzzy_transpositions\" : true,\n" +
|
||||
" \"lenient\" : false,\n" +
|
||||
" \"zero_terms_query\" : \"NONE\",\n" +
|
||||
" \"auto_generate_synonyms_phrase_query\" : true,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
MatchQueryBuilder qb = (MatchQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, qb);
|
||||
|
||||
assertEquals(json, expectedQB, qb);
|
||||
assertSerialization(qb);
|
||||
assertWarnings("Deprecated field [type] used, replaced by [match_phrase and match_phrase_prefix query]",
|
||||
"Deprecated field [slop] used, replaced by [match_phrase query]");
|
||||
}
|
||||
|
||||
public void testFuzzinessOnNonStringField() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
MatchQueryBuilder query = new MatchQueryBuilder(INT_FIELD_NAME, 42);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.elasticsearch.search.fetch.subphase.highlight;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
||||
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
|
@ -39,7 +40,6 @@ import org.elasticsearch.index.query.QueryBuilder;
|
|||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
||||
import org.elasticsearch.index.query.functionscore.RandomScoreFunctionBuilder;
|
||||
import org.elasticsearch.index.search.MatchQuery;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
|
@ -79,7 +79,6 @@ import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery;
|
|||
import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.regexpQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.typeQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.wildcardQuery;
|
||||
import static org.elasticsearch.search.builder.SearchSourceBuilder.highlight;
|
||||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
|
@ -1474,7 +1473,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
SearchResponse response = client().prepareSearch("test")
|
||||
.setQuery(QueryBuilders.matchQuery("tags", "long tag").type(MatchQuery.Type.PHRASE))
|
||||
.setQuery(QueryBuilders.matchPhraseQuery("tags", "long tag"))
|
||||
.highlighter(
|
||||
new HighlightBuilder().field(new HighlightBuilder.Field("tags")
|
||||
.highlighterType("plain").fragmentSize(-1).numOfFragments(2).fragmenter("simple")))
|
||||
|
@ -1485,7 +1484,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
equalTo("here is another one that is very <em>long</em> <em>tag</em> and has the tag token near the end"));
|
||||
|
||||
response = client().prepareSearch("test")
|
||||
.setQuery(QueryBuilders.matchQuery("tags", "long tag").type(MatchQuery.Type.PHRASE))
|
||||
.setQuery(QueryBuilders.matchPhraseQuery("tags", "long tag"))
|
||||
.highlighter(
|
||||
new HighlightBuilder().field(new Field("tags").highlighterType("plain").fragmentSize(-1).numOfFragments(2)
|
||||
.fragmenter("span"))).get();
|
||||
|
@ -1496,7 +1495,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
equalTo("here is another one that is very <em>long</em> <em>tag</em> and has the tag token near the end"));
|
||||
|
||||
assertFailures(client().prepareSearch("test")
|
||||
.setQuery(QueryBuilders.matchQuery("tags", "long tag").type(MatchQuery.Type.PHRASE))
|
||||
.setQuery(QueryBuilders.matchPhraseQuery("tags", "long tag"))
|
||||
.highlighter(
|
||||
new HighlightBuilder().field(new Field("tags").highlighterType("plain").fragmentSize(-1).numOfFragments(2)
|
||||
.fragmenter("invalid"))),
|
||||
|
@ -1554,7 +1553,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
|
||||
// This query used to fail when the field to highlight was absent
|
||||
SearchResponse response = client().prepareSearch("test")
|
||||
.setQuery(QueryBuilders.matchQuery("field", "highlight").type(MatchQuery.Type.BOOLEAN))
|
||||
.setQuery(QueryBuilders.matchQuery("field", "highlight"))
|
||||
.highlighter(
|
||||
new HighlightBuilder().field(new HighlightBuilder.Field("highlight_field").fragmentSize(-1).numOfFragments(1)
|
||||
.fragmenter("simple"))).get();
|
||||
|
@ -1579,7 +1578,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
SearchResponse response = client().prepareSearch("test")
|
||||
.setQuery(QueryBuilders.matchQuery("text", "test").type(MatchQuery.Type.BOOLEAN))
|
||||
.setQuery(QueryBuilders.matchQuery("text", "test"))
|
||||
.highlighter(
|
||||
new HighlightBuilder().field("text").field("byte").field("short").field("int").field("long").field("float")
|
||||
.field("double"))
|
||||
|
@ -1604,7 +1603,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
SearchResponse response = client().prepareSearch("test")
|
||||
.setQuery(QueryBuilders.matchQuery("text", "test").type(MatchQuery.Type.BOOLEAN))
|
||||
.setQuery(QueryBuilders.matchQuery("text", "test"))
|
||||
.highlighter(new HighlightBuilder().field("text")).execute().actionGet();
|
||||
// PatternAnalyzer will throw an exception if it is resetted twice
|
||||
assertHitCount(response, 1L);
|
||||
|
|
|
@ -179,7 +179,7 @@ public class MultiMatchQueryIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testDefaults() throws ExecutionException, InterruptedException {
|
||||
MatchQuery.Type type = randomBoolean() ? MatchQueryBuilder.DEFAULT_TYPE : MatchQuery.Type.BOOLEAN;
|
||||
MatchQuery.Type type = MatchQuery.Type.BOOLEAN;
|
||||
SearchResponse searchResponse = client().prepareSearch("test")
|
||||
.setQuery(randomizeType(multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category")
|
||||
.operator(Operator.OR))).get();
|
||||
|
@ -270,9 +270,7 @@ public class MultiMatchQueryIT extends ESIntegTestCase {
|
|||
.addSort("_id", SortOrder.ASC)
|
||||
.setQuery(multiMatchQueryBuilder).get();
|
||||
MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery(field, builder.toString());
|
||||
if (multiMatchQueryBuilder.getType() != null) {
|
||||
matchQueryBuilder.type(MatchQuery.Type.valueOf(multiMatchQueryBuilder.getType().matchQueryType().toString()));
|
||||
}
|
||||
|
||||
SearchResponse matchResp = client().prepareSearch("test")
|
||||
// _id tie sort
|
||||
.addSort("_score", SortOrder.DESC)
|
||||
|
@ -294,7 +292,7 @@ public class MultiMatchQueryIT extends ESIntegTestCase {
|
|||
public void testCutoffFreq() throws ExecutionException, InterruptedException {
|
||||
final long numDocs = client().prepareSearch("test").setSize(0)
|
||||
.setQuery(matchAllQuery()).get().getHits().getTotalHits();
|
||||
MatchQuery.Type type = randomBoolean() ? MatchQueryBuilder.DEFAULT_TYPE : MatchQuery.Type.BOOLEAN;
|
||||
MatchQuery.Type type = MatchQuery.Type.BOOLEAN;
|
||||
Float cutoffFrequency = randomBoolean() ? Math.min(1, numDocs * 1.f / between(10, 20)) : 1.f / between(10, 20);
|
||||
SearchResponse searchResponse = client().prepareSearch("test")
|
||||
.setQuery(randomizeType(multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category")
|
||||
|
@ -357,7 +355,7 @@ public class MultiMatchQueryIT extends ESIntegTestCase {
|
|||
int numIters = scaledRandomIntBetween(5, 10);
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
{
|
||||
MatchQuery.Type type = randomBoolean() ? MatchQueryBuilder.DEFAULT_TYPE : MatchQuery.Type.BOOLEAN;
|
||||
MatchQuery.Type type = MatchQuery.Type.BOOLEAN;
|
||||
MultiMatchQueryBuilder multiMatchQueryBuilder = randomBoolean() ? multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category") :
|
||||
multiMatchQuery("marvel hero captain america", "*_name", randomBoolean() ? "category" : "categ*");
|
||||
SearchResponse left = client().prepareSearch("test").setSize(numDocs)
|
||||
|
@ -377,7 +375,7 @@ public class MultiMatchQueryIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
{
|
||||
MatchQuery.Type type = randomBoolean() ? MatchQueryBuilder.DEFAULT_TYPE : MatchQuery.Type.BOOLEAN;
|
||||
MatchQuery.Type type = MatchQuery.Type.BOOLEAN;
|
||||
String minShouldMatch = randomBoolean() ? null : "" + between(0, 1);
|
||||
Operator op = randomBoolean() ? Operator.AND : Operator.OR;
|
||||
MultiMatchQueryBuilder multiMatchQueryBuilder = randomBoolean() ? multiMatchQuery("captain america", "full_name", "first_name", "last_name", "category") :
|
||||
|
|
|
@ -35,12 +35,10 @@ import org.elasticsearch.index.query.MatchQueryBuilder;
|
|||
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
|
||||
import org.elasticsearch.index.query.Operator;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.RangeQueryBuilder;
|
||||
import org.elasticsearch.index.query.TermQueryBuilder;
|
||||
import org.elasticsearch.index.query.WrapperQueryBuilder;
|
||||
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
|
||||
import org.elasticsearch.index.search.MatchQuery;
|
||||
import org.elasticsearch.index.search.MatchQuery.Type;
|
||||
import org.elasticsearch.indices.TermsLookup;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
@ -70,6 +68,8 @@ import static org.elasticsearch.index.query.QueryBuilders.functionScoreQuery;
|
|||
import static org.elasticsearch.index.query.QueryBuilders.fuzzyQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.idsQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchPhrasePrefixQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchPhraseQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.multiMatchQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.prefixQuery;
|
||||
|
@ -99,7 +99,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSeco
|
|||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThirdHit;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasScore;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.closeTo;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -173,10 +172,10 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
client().prepareIndex("test", "type1", "1").setSource("field1", "quick brown fox", "field2", "quick brown fox"),
|
||||
client().prepareIndex("test", "type1", "2").setSource("field1", "quick lazy huge brown fox", "field2", "quick lazy huge brown fox"));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch().setQuery(matchQuery("field2", "quick brown").type(Type.PHRASE).slop(0)).get();
|
||||
SearchResponse searchResponse = client().prepareSearch().setQuery(matchPhraseQuery("field2", "quick brown").slop(0)).get();
|
||||
assertHitCount(searchResponse, 1L);
|
||||
|
||||
assertFailures(client().prepareSearch().setQuery(matchQuery("field1", "quick brown").type(Type.PHRASE).slop(0)),
|
||||
assertFailures(client().prepareSearch().setQuery(matchPhraseQuery("field1", "quick brown").slop(0)),
|
||||
RestStatus.BAD_REQUEST,
|
||||
containsString("field:[field1] was indexed without position data; cannot run PhraseQuery"));
|
||||
}
|
||||
|
@ -1407,7 +1406,7 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
|
||||
searchResponse = client().prepareSearch("test").setQuery(
|
||||
boolQuery()
|
||||
.mustNot(matchQuery("description", "anything").type(Type.BOOLEAN))
|
||||
.mustNot(matchQuery("description", "anything"))
|
||||
).setSearchType(SearchType.DFS_QUERY_THEN_FETCH).get();
|
||||
assertHitCount(searchResponse, 2L);
|
||||
}
|
||||
|
@ -1853,13 +1852,14 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
client().prepareIndex("test1", "type1", "2").setSource("field", "trying out Elasticsearch"));
|
||||
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch().setQuery(matchQuery("field", "Johnnie la").slop(between(2,5)).type(Type.PHRASE_PREFIX)).get();
|
||||
SearchResponse searchResponse = client().prepareSearch().setQuery(matchPhrasePrefixQuery("field", "Johnnie la").slop(between(2, 5)))
|
||||
.get();
|
||||
assertHitCount(searchResponse, 1L);
|
||||
assertSearchHits(searchResponse, "1");
|
||||
searchResponse = client().prepareSearch().setQuery(matchQuery("field", "trying").type(Type.PHRASE_PREFIX)).get();
|
||||
searchResponse = client().prepareSearch().setQuery(matchPhrasePrefixQuery("field", "trying")).get();
|
||||
assertHitCount(searchResponse, 1L);
|
||||
assertSearchHits(searchResponse, "2");
|
||||
searchResponse = client().prepareSearch().setQuery(matchQuery("field", "try").type(Type.PHRASE_PREFIX)).get();
|
||||
searchResponse = client().prepareSearch().setQuery(matchPhrasePrefixQuery("field", "try")).get();
|
||||
assertHitCount(searchResponse, 1L);
|
||||
assertSearchHits(searchResponse, "2");
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.elasticsearch.ResourceNotFoundException;
|
|||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse;
|
||||
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
|
@ -283,8 +282,10 @@ public class SearchTemplateIT extends ESSingleNodeTestCase {
|
|||
for (int i = 1; i < iterations; i++) {
|
||||
assertAcked(client().admin().cluster().preparePutStoredScript()
|
||||
.setId("git01")
|
||||
.setContent(new BytesArray("{\"template\":{\"query\": {\"match\": {\"searchtext\": {\"query\": \"{{P_Keyword1}}\"," +
|
||||
"\"type\": \"ooophrase_prefix\"}}}}}"), XContentType.JSON));
|
||||
.setContent(new BytesArray(
|
||||
"{\"template\":{\"query\": {\"match_phrase_prefix\": {\"searchtext\": {\"query\": \"{{P_Keyword1}}\","
|
||||
+ "\"slop\": -1}}}}}"),
|
||||
XContentType.JSON));
|
||||
|
||||
GetStoredScriptResponse getResponse = client().admin().cluster().prepareGetStoredScript("git01").get();
|
||||
assertNotNull(getResponse.getSource());
|
||||
|
@ -292,24 +293,22 @@ public class SearchTemplateIT extends ESSingleNodeTestCase {
|
|||
Map<String, Object> templateParams = new HashMap<>();
|
||||
templateParams.put("P_Keyword1", "dev");
|
||||
|
||||
ParsingException e = expectThrows(ParsingException.class, () -> new SearchTemplateRequestBuilder(client())
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new SearchTemplateRequestBuilder(client())
|
||||
.setRequest(new SearchRequest("testindex").types("test"))
|
||||
.setScript("git01").setScriptType(ScriptType.STORED).setScriptParams(templateParams)
|
||||
.get());
|
||||
assertThat(e.getMessage(), containsString("[match] query does not support type ooophrase_prefix"));
|
||||
assertWarnings("Deprecated field [type] used, replaced by [match_phrase and match_phrase_prefix query]");
|
||||
assertThat(e.getMessage(), containsString("No negative slop allowed"));
|
||||
|
||||
assertAcked(client().admin().cluster().preparePutStoredScript()
|
||||
.setId("git01")
|
||||
.setContent(new BytesArray("{\"query\": {\"match\": {\"searchtext\": {\"query\": \"{{P_Keyword1}}\"," +
|
||||
"\"type\": \"phrase_prefix\"}}}}"), XContentType.JSON));
|
||||
.setContent(new BytesArray("{\"query\": {\"match_phrase_prefix\": {\"searchtext\": {\"query\": \"{{P_Keyword1}}\"," +
|
||||
"\"slop\": 0}}}}"), XContentType.JSON));
|
||||
|
||||
SearchTemplateResponse searchResponse = new SearchTemplateRequestBuilder(client())
|
||||
.setRequest(new SearchRequest("testindex").types("test"))
|
||||
.setScript("git01").setScriptType(ScriptType.STORED).setScriptParams(templateParams)
|
||||
.get();
|
||||
assertHitCount(searchResponse.getResponse(), 1);
|
||||
assertWarnings("Deprecated field [type] used, replaced by [match_phrase and match_phrase_prefix query]");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue