Skip to content

Commit 56888af

Browse files
Add boost field
1 parent 665c32e commit 56888af

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public final class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatc
5353
public static final ZeroTermsQueryOption DEFAULT_ZERO_TERMS_QUERY = MatchQueryParser.DEFAULT_ZERO_TERMS_QUERY;
5454
public static final boolean DEFAULT_FUZZY_TRANSPOSITIONS = FuzzyQuery.defaultTranspositions;
5555

56+
public static final ParseField BOOST_FIELD = new ParseField("boost");
5657
public static final ParseField SLOP_FIELD = new ParseField("slop");
5758
public static final ParseField ZERO_TERMS_QUERY_FIELD = new ParseField("zero_terms_query");
5859
public static final ParseField LENIENT_FIELD = new ParseField("lenient");

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/MultiMatch.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
import static java.util.Map.entry;
4848
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.ANALYZER_FIELD;
49+
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.BOOST_FIELD;
4950
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.FUZZINESS_FIELD;
5051
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.FUZZY_REWRITE_FIELD;
5152
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.FUZZY_TRANSPOSITIONS_FIELD;
@@ -116,6 +117,7 @@ public class MultiMatch extends FullTextFunction implements OptionalArgument, Po
116117
);
117118

118119
public static final Map<String, DataType> OPTIONS = Map.ofEntries(
120+
entry(BOOST_FIELD.getPreferredName(), FLOAT),
119121
entry(SLOP_FIELD.getPreferredName(), INTEGER),
120122
// TODO: add "zero_terms_query"
121123
entry(ANALYZER_FIELD.getPreferredName(), KEYWORD),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import static java.util.Map.entry;
2323
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.ANALYZER_FIELD;
24+
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.BOOST_FIELD;
2425
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.FUZZINESS_FIELD;
2526
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.FUZZY_REWRITE_FIELD;
2627
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.FUZZY_TRANSPOSITIONS_FIELD;
@@ -40,6 +41,7 @@ public class MultiMatchQuery extends Query {
4041

4142
static {
4243
BUILDER_APPLIERS = Map.ofEntries(
44+
entry(BOOST_FIELD.getPreferredName(), (qb, obj) -> qb.boost((Float) obj)),
4345
entry(SLOP_FIELD.getPreferredName(), (qb, obj) -> qb.slop((Integer) obj)),
4446
// TODO: add zero terms query support, I'm not sure the best way to parse it yet...
4547
// appliers.put("zero_terms_query", (qb, s) -> qb.zeroTermsQuery(s));

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LocalPhysicalPlanOptimizerTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ public void testMultiMatchOptionsPushDown() {
16641664
| where MULTI_MATCH("Anna", first_name, last_name, {"fuzzy_rewrite": "constant_score", "slop": 10, "analyzer": "auto",
16651665
"auto_generate_synonyms_phrase_query": "false", "fuzziness": "auto", "fuzzy_transpositions": false, "lenient": "false",
16661666
"max_expansions": 10, "minimum_should_match": 3, "operator": "AND", "prefix_length": 20, "tie_breaker": 1.0,
1667-
"type": "best_fields"})
1667+
"type": "best_fields", "boost": 2.0})
16681668
""";
16691669
var plan = plannerOptimizer.plan(query);
16701670

@@ -1673,6 +1673,7 @@ public void testMultiMatchOptionsPushDown() {
16731673

16741674
var expectedQuery = new MultiMatchQueryBuilder("Anna").fields(Map.of("first_name", 1.0f, "last_name", 1.0f))
16751675
.slop(10)
1676+
.boost(2.0f)
16761677
.analyzer("auto")
16771678
.autoGenerateSynonymsPhraseQuery(false)
16781679
.operator(Operator.fromString("AND"))

0 commit comments

Comments
 (0)