Skip to content

Commit c1d4157

Browse files
Add fuzzy_rewrite field
1 parent 70ffeac commit c1d4157

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
5151
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.ANALYZER_FIELD;
5252
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.FUZZINESS_FIELD;
53+
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.FUZZY_REWRITE_FIELD;
5354
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.FUZZY_TRANSPOSITIONS_FIELD;
5455
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.GENERATE_SYNONYMS_PHRASE_QUERY;
5556
import static org.elasticsearch.index.query.MultiMatchQueryBuilder.LENIENT_FIELD;
@@ -124,6 +125,7 @@ public class MultiMatch extends FullTextFunction implements OptionalArgument, Po
124125
entry(ANALYZER_FIELD.getPreferredName(), KEYWORD),
125126
entry(GENERATE_SYNONYMS_PHRASE_QUERY.getPreferredName(), BOOLEAN),
126127
entry(FUZZINESS_FIELD.getPreferredName(), KEYWORD),
128+
entry(FUZZY_REWRITE_FIELD.getPreferredName(), KEYWORD),
127129
entry(FUZZY_TRANSPOSITIONS_FIELD.getPreferredName(), BOOLEAN),
128130
entry(LENIENT_FIELD.getPreferredName(), BOOLEAN),
129131
entry(MAX_EXPANSIONS_FIELD.getPreferredName(), INTEGER),
@@ -190,6 +192,20 @@ public MultiMatch(
190192
valueHint = { "AUTO", "1", "2" },
191193
description = "Maximum edit distance allowed for matching."
192194
),
195+
@MapParam.MapParamEntry(
196+
name = "fuzzy_rewrite",
197+
type = "keyword",
198+
valueHint = {
199+
"constant_score_blended",
200+
"constant_score",
201+
"constant_score_boolean",
202+
"top_terms_blended_freqs_N",
203+
"top_terms_boost_N",
204+
"top_terms_N" },
205+
description = "Method used to rewrite the query. See the rewrite parameter for valid values and more information. "
206+
+ "If the fuzziness parameter is not 0, the match query uses a fuzzy_rewrite method of "
207+
+ "top_terms_blended_freqs_${max_expansions} by default."
208+
),
193209
@MapParam.MapParamEntry(
194210
name = "fuzzy_transpositions",
195211
type = "boolean",

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
@@ -1660,7 +1660,7 @@ public void testQStrOptionsPushDown() {
16601660
public void testMultiMatchOptionsPushDown() {
16611661
String query = """
16621662
from test
1663-
| where MULTI_MATCH("Anna", first_name, last_name, {"slop": 10, "analyzer": "auto",
1663+
| where MULTI_MATCH("Anna", first_name, last_name, {"fuzzy_rewrite": "constant_score", "slop": 10, "analyzer": "auto",
16641664
"auto_generate_synonyms_phrase_query": "false", "fuzziness": "auto", "fuzzy_transpositions": false, "lenient": "false",
16651665
"max_expansions": 10, "minimum_should_match": 3, "operator": "AND", "prefix_length": 20, "tie_breaker": 1.0,
16661666
"type": "best_fields"})
@@ -1676,6 +1676,7 @@ public void testMultiMatchOptionsPushDown() {
16761676
.autoGenerateSynonymsPhraseQuery(false)
16771677
.operator(Operator.fromString("AND"))
16781678
.fuzziness(Fuzziness.fromString("auto"))
1679+
.fuzzyRewrite("constant_score")
16791680
.fuzzyTranspositions(false)
16801681
.lenient(false)
16811682
.maxExpansions(10)

0 commit comments

Comments
 (0)