Skip to content

Commit b33ff16

Browse files
author
Christoph Büscher
authored
Remove deprecated useDisMax from MultiMatchQuery (#36488)
The getters and setters for useDisMax() have been deprecated since at least 6.0, also there hasn't been any reference to the query parameter in the documentation. Removing it from the builder and tests and replacing it with `tieBreaker(1.0f)` where necessary.
1 parent 4b17055 commit b33ff16

File tree

7 files changed

+25
-63
lines changed

7 files changed

+25
-63
lines changed

server/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
6767
private static final ParseField LENIENT_FIELD = new ParseField("lenient");
6868
private static final ParseField CUTOFF_FREQUENCY_FIELD = new ParseField("cutoff_frequency");
6969
private static final ParseField TIE_BREAKER_FIELD = new ParseField("tie_breaker");
70-
private static final ParseField USE_DIS_MAX_FIELD = new ParseField("use_dis_max");
7170
private static final ParseField FUZZY_REWRITE_FIELD = new ParseField("fuzzy_rewrite");
7271
private static final ParseField MINIMUM_SHOULD_MATCH_FIELD = new ParseField("minimum_should_match");
7372
private static final ParseField OPERATOR_FIELD = new ParseField("operator");
@@ -92,7 +91,6 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
9291
private int maxExpansions = DEFAULT_MAX_EXPANSIONS;
9392
private String minimumShouldMatch;
9493
private String fuzzyRewrite = null;
95-
private Boolean useDisMax;
9694
private Float tieBreaker;
9795
private Boolean lenient;
9896
private Float cutoffFrequency = null;
@@ -224,7 +222,9 @@ public MultiMatchQueryBuilder(StreamInput in) throws IOException {
224222
maxExpansions = in.readVInt();
225223
minimumShouldMatch = in.readOptionalString();
226224
fuzzyRewrite = in.readOptionalString();
227-
useDisMax = in.readOptionalBoolean();
225+
if (in.getVersion().before(Version.V_7_0_0)) {
226+
in.readOptionalBoolean(); // unused use_dis_max flag
227+
}
228228
tieBreaker = in.readOptionalFloat();
229229
if (in.getVersion().onOrAfter(Version.V_6_1_0)) {
230230
lenient = in.readOptionalBoolean();
@@ -256,7 +256,9 @@ protected void doWriteTo(StreamOutput out) throws IOException {
256256
out.writeVInt(maxExpansions);
257257
out.writeOptionalString(minimumShouldMatch);
258258
out.writeOptionalString(fuzzyRewrite);
259-
out.writeOptionalBoolean(useDisMax);
259+
if (out.getVersion().before(Version.V_7_0_0)) {
260+
out.writeOptionalBoolean(null);
261+
}
260262
out.writeOptionalFloat(tieBreaker);
261263
if (out.getVersion().onOrAfter(Version.V_6_1_0)) {
262264
out.writeOptionalBoolean(lenient);
@@ -438,20 +440,6 @@ public String fuzzyRewrite() {
438440
return fuzzyRewrite;
439441
}
440442

441-
/**
442-
* @deprecated use a tieBreaker of 1.0f to disable "dis-max"
443-
* query or select the appropriate {@link Type}
444-
*/
445-
@Deprecated
446-
public MultiMatchQueryBuilder useDisMax(Boolean useDisMax) {
447-
this.useDisMax = useDisMax;
448-
return this;
449-
}
450-
451-
public Boolean useDisMax() {
452-
return useDisMax;
453-
}
454-
455443
/**
456444
* <p>Tie-Breaker for "best-match" disjunction queries (OR-Queries).
457445
* The tie breaker capability allows documents that match more than one query clause
@@ -593,9 +581,6 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio
593581
if (fuzzyRewrite != null) {
594582
builder.field(FUZZY_REWRITE_FIELD.getPreferredName(), fuzzyRewrite);
595583
}
596-
if (useDisMax != null) {
597-
builder.field(USE_DIS_MAX_FIELD.getPreferredName(), useDisMax);
598-
}
599584
if (tieBreaker != null) {
600585
builder.field(TIE_BREAKER_FIELD.getPreferredName(), tieBreaker);
601586
}
@@ -674,8 +659,6 @@ public static MultiMatchQueryBuilder fromXContent(XContentParser parser) throws
674659
minimumShouldMatch = parser.textOrNull();
675660
} else if (FUZZY_REWRITE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
676661
fuzzyRewrite = parser.textOrNull();
677-
} else if (USE_DIS_MAX_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
678-
useDisMax = parser.booleanValue();
679662
} else if (TIE_BREAKER_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
680663
tieBreaker = parser.floatValue();
681664
} else if (CUTOFF_FREQUENCY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
@@ -724,7 +707,6 @@ public static MultiMatchQueryBuilder fromXContent(XContentParser parser) throws
724707
.cutoffFrequency(cutoffFrequency)
725708
.fuzziness(fuzziness)
726709
.fuzzyRewrite(fuzzyRewrite)
727-
.useDisMax(useDisMax)
728710
.maxExpansions(maxExpansions)
729711
.minimumShouldMatch(minimumShouldMatch)
730712
.operator(operator)
@@ -798,16 +780,6 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
798780
multiMatchQuery.setAutoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery);
799781
multiMatchQuery.setTranspositions(fuzzyTranspositions);
800782

801-
if (useDisMax != null) { // backwards foobar
802-
boolean typeUsesDismax = type.tieBreaker() != 1.0f;
803-
if (typeUsesDismax != useDisMax) {
804-
if (useDisMax && tieBreaker == null) {
805-
multiMatchQuery.setTieBreaker(0.0f);
806-
} else {
807-
multiMatchQuery.setTieBreaker(1.0f);
808-
}
809-
}
810-
}
811783
Map<String, Float> newFieldsBoosts;
812784
if (fieldsBoosts.isEmpty()) {
813785
// no fields provided, defaults to index.query.default_field
@@ -828,7 +800,7 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
828800
@Override
829801
protected int doHashCode() {
830802
return Objects.hash(value, fieldsBoosts, type, operator, analyzer, slop, fuzziness,
831-
prefixLength, maxExpansions, minimumShouldMatch, fuzzyRewrite, useDisMax, tieBreaker, lenient,
803+
prefixLength, maxExpansions, minimumShouldMatch, fuzzyRewrite, tieBreaker, lenient,
832804
cutoffFrequency, zeroTermsQuery, autoGenerateSynonymsPhraseQuery, fuzzyTranspositions);
833805
}
834806

@@ -845,7 +817,6 @@ protected boolean doEquals(MultiMatchQueryBuilder other) {
845817
Objects.equals(maxExpansions, other.maxExpansions) &&
846818
Objects.equals(minimumShouldMatch, other.minimumShouldMatch) &&
847819
Objects.equals(fuzzyRewrite, other.fuzzyRewrite) &&
848-
Objects.equals(useDisMax, other.useDisMax) &&
849820
Objects.equals(tieBreaker, other.tieBreaker) &&
850821
Objects.equals(lenient, other.lenient) &&
851822
Objects.equals(cutoffFrequency, other.cutoffFrequency) &&

server/src/test/java/org/elasticsearch/index/query/MultiMatchQueryBuilderTests.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ protected MultiMatchQueryBuilder doCreateTestQueryBuilder() {
118118
if (randomBoolean()) {
119119
query.fuzzyRewrite(getRandomRewriteMethod());
120120
}
121-
if (randomBoolean()) {
122-
query.useDisMax(randomBoolean());
123-
}
124121
if (randomBoolean()) {
125122
query.tieBreaker(randomFloat());
126123
}
@@ -189,7 +186,7 @@ public void testToQueryBoost() throws IOException {
189186
}
190187

191188
public void testToQueryMultipleTermsBooleanQuery() throws Exception {
192-
Query query = multiMatchQuery("test1 test2").field(STRING_FIELD_NAME).useDisMax(false).toQuery(createShardContext());
189+
Query query = multiMatchQuery("test1 test2").field(STRING_FIELD_NAME).toQuery(createShardContext());
193190
assertThat(query, instanceOf(BooleanQuery.class));
194191
BooleanQuery bQuery = (BooleanQuery) query;
195192
assertThat(bQuery.clauses().size(), equalTo(2));
@@ -198,8 +195,8 @@ public void testToQueryMultipleTermsBooleanQuery() throws Exception {
198195
}
199196

200197
public void testToQueryMultipleFieldsDisableDismax() throws Exception {
201-
Query query = multiMatchQuery("test").field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2).useDisMax(false)
202-
.toQuery(createShardContext());
198+
Query query = multiMatchQuery("test").field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2).tieBreaker(1.0f)
199+
.toQuery(createShardContext());
203200
assertThat(query, instanceOf(DisjunctionMaxQuery.class));
204201
DisjunctionMaxQuery dQuery = (DisjunctionMaxQuery) query;
205202
assertThat(dQuery.getTieBreakerMultiplier(), equalTo(1.0f));
@@ -209,8 +206,7 @@ public void testToQueryMultipleFieldsDisableDismax() throws Exception {
209206
}
210207

211208
public void testToQueryMultipleFieldsDisMaxQuery() throws Exception {
212-
Query query = multiMatchQuery("test").field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2).useDisMax(true)
213-
.toQuery(createShardContext());
209+
Query query = multiMatchQuery("test").field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2).toQuery(createShardContext());
214210
assertThat(query, instanceOf(DisjunctionMaxQuery.class));
215211
DisjunctionMaxQuery disMaxQuery = (DisjunctionMaxQuery) query;
216212
assertThat(disMaxQuery.getTieBreakerMultiplier(), equalTo(0.0f));
@@ -222,7 +218,7 @@ public void testToQueryMultipleFieldsDisMaxQuery() throws Exception {
222218
}
223219

224220
public void testToQueryFieldsWildcard() throws Exception {
225-
Query query = multiMatchQuery("test").field("mapped_str*").useDisMax(false).toQuery(createShardContext());
221+
Query query = multiMatchQuery("test").field("mapped_str*").tieBreaker(1.0f).toQuery(createShardContext());
226222
assertThat(query, instanceOf(DisjunctionMaxQuery.class));
227223
DisjunctionMaxQuery dQuery = (DisjunctionMaxQuery) query;
228224
assertThat(dQuery.getTieBreakerMultiplier(), equalTo(1.0f));

server/src/test/java/org/elasticsearch/search/query/MultiMatchQueryIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public void testDefaults() throws ExecutionException, InterruptedException {
203203

204204
searchResponse = client().prepareSearch("test")
205205
.setQuery(randomizeType(multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category")
206-
.operator(Operator.OR).useDisMax(false).type(type))).get();
206+
.operator(Operator.OR).type(type))).get();
207207
assertFirstHit(searchResponse, anyOf(hasId("theone"), hasId("theother")));
208208
assertThat(searchResponse.getHits().getHits()[0].getScore(), greaterThan(searchResponse.getHits().getHits()[1].getScore()));
209209

@@ -323,14 +323,14 @@ public void testCutoffFreq() throws ExecutionException, InterruptedException {
323323
cutoffFrequency = randomBoolean() ? Math.min(1, numDocs * 1.f / between(10, 20)) : 1.f / between(10, 20);
324324
searchResponse = client().prepareSearch("test")
325325
.setQuery(randomizeType(multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category")
326-
.operator(Operator.OR).useDisMax(false).cutoffFrequency(cutoffFrequency).type(type))).get();
326+
.operator(Operator.OR).cutoffFrequency(cutoffFrequency).type(type))).get();
327327
assertFirstHit(searchResponse, anyOf(hasId("theone"), hasId("theother")));
328328
assertThat(searchResponse.getHits().getHits()[0].getScore(), greaterThan(searchResponse.getHits().getHits()[1].getScore()));
329329
long size = searchResponse.getHits().getTotalHits().value;
330330

331331
searchResponse = client().prepareSearch("test")
332332
.setQuery(randomizeType(multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category")
333-
.operator(Operator.OR).useDisMax(false).type(type))).get();
333+
.operator(Operator.OR).type(type))).get();
334334
assertFirstHit(searchResponse, anyOf(hasId("theone"), hasId("theother")));
335335
assertThat("common terms expected to be a way smaller result set", size, lessThan(searchResponse.getHits().getTotalHits().value));
336336

@@ -399,7 +399,7 @@ public void testEquivalence() {
399399
SearchResponse left = client().prepareSearch("test").setSize(numDocs)
400400
.addSort(SortBuilders.scoreSort()).addSort(SortBuilders.fieldSort("_id"))
401401
.setQuery(randomizeType(multiMatchQueryBuilder
402-
.operator(op).useDisMax(false).minimumShouldMatch(minShouldMatch).type(type))).get();
402+
.operator(op).tieBreaker(1.0f).minimumShouldMatch(minShouldMatch).type(type))).get();
403403

404404
SearchResponse right = client().prepareSearch("test").setSize(numDocs)
405405
.addSort(SortBuilders.scoreSort()).addSort(SortBuilders.fieldSort("_id"))
@@ -418,7 +418,7 @@ public void testEquivalence() {
418418
SearchResponse left = client().prepareSearch("test").setSize(numDocs)
419419
.addSort(SortBuilders.scoreSort()).addSort(SortBuilders.fieldSort("_id"))
420420
.setQuery(randomizeType(multiMatchQuery("capta", "full_name", "first_name", "last_name", "category")
421-
.type(MatchQuery.Type.PHRASE_PREFIX).useDisMax(false).minimumShouldMatch(minShouldMatch))).get();
421+
.type(MatchQuery.Type.PHRASE_PREFIX).tieBreaker(1.0f).minimumShouldMatch(minShouldMatch))).get();
422422

423423
SearchResponse right = client().prepareSearch("test").setSize(numDocs)
424424
.addSort(SortBuilders.scoreSort()).addSort(SortBuilders.fieldSort("_id"))
@@ -437,7 +437,7 @@ public void testEquivalence() {
437437
left = client().prepareSearch("test").setSize(numDocs)
438438
.addSort(SortBuilders.scoreSort()).addSort(SortBuilders.fieldSort("_id"))
439439
.setQuery(randomizeType(multiMatchQuery("captain america", "full_name", "first_name", "last_name", "category")
440-
.type(MatchQuery.Type.PHRASE).useDisMax(false).minimumShouldMatch(minShouldMatch))).get();
440+
.type(MatchQuery.Type.PHRASE).minimumShouldMatch(minShouldMatch))).get();
441441
} else {
442442
left = client().prepareSearch("test").setSize(numDocs)
443443
.addSort(SortBuilders.scoreSort()).addSort(SortBuilders.fieldSort("_id"))

server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ public void testMultiMatchQuery() throws Exception {
681681
// this uses dismax so scores are equal and the order can be arbitrary
682682
assertSearchHits(searchResponse, "1", "2");
683683

684-
builder.useDisMax(false);
685684
searchResponse = client().prepareSearch()
686685
.setQuery(builder)
687686
.get();
@@ -786,7 +785,6 @@ public void testMultiMatchQueryMinShouldMatch() {
786785

787786
MultiMatchQueryBuilder multiMatchQuery = multiMatchQuery("value1 value2 foo", "field1", "field2");
788787

789-
multiMatchQuery.useDisMax(true);
790788
multiMatchQuery.minimumShouldMatch("70%");
791789
SearchResponse searchResponse = client().prepareSearch()
792790
.setQuery(multiMatchQuery)
@@ -800,7 +798,6 @@ public void testMultiMatchQueryMinShouldMatch() {
800798
assertFirstHit(searchResponse, hasId("1"));
801799
assertSecondHit(searchResponse, hasId("2"));
802800

803-
multiMatchQuery.useDisMax(false);
804801
multiMatchQuery.minimumShouldMatch("70%");
805802
searchResponse = client().prepareSearch().setQuery(multiMatchQuery).get();
806803
assertHitCount(searchResponse, 1L);
@@ -1475,11 +1472,11 @@ public void testMultiMatchLenientIssue3797() {
14751472
refresh();
14761473

14771474
SearchResponse searchResponse = client().prepareSearch("test")
1478-
.setQuery(multiMatchQuery("value2", "field2").field("field1", 2).lenient(true).useDisMax(false)).get();
1475+
.setQuery(multiMatchQuery("value2", "field2").field("field1", 2).lenient(true)).get();
14791476
assertHitCount(searchResponse, 1L);
14801477

14811478
searchResponse = client().prepareSearch("test")
1482-
.setQuery(multiMatchQuery("value2", "field2").field("field1", 2).lenient(true).useDisMax(true)).get();
1479+
.setQuery(multiMatchQuery("value2", "field2").field("field1", 2).lenient(true)).get();
14831480
assertHitCount(searchResponse, 1L);
14841481

14851482
searchResponse = client().prepareSearch("test")

x-pack/plugin/sql/qa/src/main/resources/fulltext.csv-spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH('first_na
5959
;
6060

6161
multiMatchQueryAllOptions
62-
SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH('first_name,last_name', 'Morton', 'slop=1;lenient=true;cutoff_frequency=2;tie_breaker=0.1;use_dis_max=true;fuzzy_rewrite=scoring_boolean;minimum_should_match=1;operator=AND;max_expansions=30;prefix_length=1;analyzer=english;type=best_fields;auto_generate_synonyms_phrase_query=true;fuzzy_transpositions=true');
62+
SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH('first_name,last_name', 'Morton', 'slop=1;lenient=true;cutoff_frequency=2;tie_breaker=0.1;fuzzy_rewrite=scoring_boolean;minimum_should_match=1;operator=AND;max_expansions=30;prefix_length=1;analyzer=english;type=best_fields;auto_generate_synonyms_phrase_query=true;fuzzy_transpositions=true');
6363

6464
emp_no:i | first_name:s | gender:s | last_name:s
6565
10095 |Hilari |M |Morton
6666
;
6767

6868
multiMatchQueryWithInMultipleCommaSeparatedStrings
69-
SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH('first_name,last_name', 'Morton', 'slop=1;lenient=true', 'cutoff_frequency=2','tie_breaker=0.1;use_dis_max=true;fuzzy_rewrite=scoring_boolean','minimum_should_match=1;operator=AND;max_expansions=30;prefix_length=1;analyzer=english;type=best_fields;auto_generate_synonyms_phrase_query=true;fuzzy_transpositions=true');
69+
SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH('first_name,last_name', 'Morton', 'slop=1;lenient=true', 'cutoff_frequency=2','tie_breaker=0.1;fuzzy_rewrite=scoring_boolean','minimum_should_match=1;operator=AND;max_expansions=30;prefix_length=1;analyzer=english;type=best_fields;auto_generate_synonyms_phrase_query=true;fuzzy_transpositions=true');
7070

7171
emp_no:i | first_name:s | gender:s | last_name:s
7272
10095 |Hilari |M |Morton

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MultiMatchQuery.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
package org.elasticsearch.xpack.sql.querydsl.query;
77

88
import org.elasticsearch.common.Booleans;
9-
import org.elasticsearch.index.query.Operator;
10-
import org.elasticsearch.index.query.QueryBuilders;
119
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
10+
import org.elasticsearch.index.query.Operator;
1211
import org.elasticsearch.index.query.QueryBuilder;
12+
import org.elasticsearch.index.query.QueryBuilders;
1313
import org.elasticsearch.xpack.sql.expression.predicate.fulltext.MultiMatchQueryPredicate;
1414
import org.elasticsearch.xpack.sql.tree.Location;
1515

@@ -32,7 +32,6 @@ public class MultiMatchQuery extends LeafQuery {
3232
appliers.put("lenient", (qb, s) -> qb.lenient(Booleans.parseBoolean(s)));
3333
appliers.put("cutoff_frequency", (qb, s) -> qb.cutoffFrequency(Float.valueOf(s)));
3434
appliers.put("tie_breaker", (qb, s) -> qb.tieBreaker(Float.valueOf(s)));
35-
appliers.put("use_dis_max", (qb, s) -> qb.useDisMax(Booleans.parseBoolean(s)));
3635
appliers.put("fuzzy_rewrite", (qb, s) -> qb.fuzzyRewrite(s));
3736
appliers.put("minimum_should_match", (qb, s) -> qb.minimumShouldMatch(s));
3837
appliers.put("operator", (qb, s) -> qb.operator(Operator.fromString(s)));

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/querydsl/query/MultiMatchQueryTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ public void testQueryBuilding() {
2323
MultiMatchQueryBuilder qb = getBuilder("lenient=true");
2424
assertThat(qb.lenient(), equalTo(true));
2525

26-
qb = getBuilder("use_dis_max=true;type=best_fields");
27-
assertThat(qb.useDisMax(), equalTo(true));
26+
qb = getBuilder("type=best_fields");
2827
assertThat(qb.getType(), equalTo(MultiMatchQueryBuilder.Type.BEST_FIELDS));
2928

3029
Exception e = expectThrows(IllegalArgumentException.class, () -> getBuilder("pizza=yummy"));

0 commit comments

Comments
 (0)