Skip to content

Commit 8427114

Browse files
svilen-mihaylov-elasticelasticsearchmachine
andauthored
[9.0] Added optional parameters to QSTR ES|QL function (elastic#121787) (elastic#125114)
* Added optional parameters to QSTR ES|QL function (elastic#121787) Adds options to QSTR function. elastic#118619 added named function parameters. This PR uses this mechanism for allowing query string function parameters, so query string parameters can be used in ES|QL. Closes elastic#120933 (cherry picked from commit ee4bcac) # Conflicts: # x-pack/plugin/esql/qa/testFixtures/src/main/resources/qstr-function.csv-spec # x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerTests.java * [CI] Auto commit changes from spotless * Fix compilation error * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
1 parent a1fba10 commit 8427114

File tree

16 files changed

+758
-109
lines changed

16 files changed

+758
-109
lines changed

docs/changelog/121787.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 121787
2+
summary: Added optional parameters to QSTR ES|QL function
3+
area: Search
4+
type: feature
5+
issues:
6+
- 120933
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
2+
3+
*Supported function named parameters*
4+
5+
[%header.monospaced.styled,format=dsv,separator=|]
6+
|===
7+
name | types | description
8+
max_determinized_states | [integer] | Maximum number of automaton states required for the query. Default is 10000.
9+
fuzziness | [keyword] | Maximum edit distance allowed for matching.
10+
auto_generate_synonyms_phrase_query | [boolean] | If true, match phrase queries are automatically created for multi-term synonyms.
11+
phrase_slop | [integer] | Maximum number of positions allowed between matching tokens for phrases.
12+
default_field | [keyword] | Default field to search if no field is provided in the query string. Supports wildcards (*).
13+
allow_leading_wildcard | [boolean] | If true, the wildcard characters * and ? are allowed as the first character of the query string.
14+
minimum_should_match | [string] | Minimum number of clauses that must match for a document to be returned.
15+
fuzzy_transpositions | [boolean] | If true, edits for fuzzy matching include transpositions of two adjacent characters (ab → ba).
16+
fuzzy_prefix_length | [integer] | Number of beginning characters left unchanged for fuzzy matching. Defaults to 0.
17+
time_zone | [keyword] | Coordinated Universal Time (UTC) offset or IANA time zone used to convert date values in the query string to UTC.
18+
lenient | [boolean] | If false, format-based errors, such as providing a text query value for a numeric field, are returned.
19+
rewrite | [keyword] | Method used to rewrite the query.
20+
default_operator | [keyword] | Default boolean logic used to interpret text in the query string if no operators are specified.
21+
analyzer | [keyword] | Analyzer used to convert the text in the query value into token.
22+
fuzzy_max_expansions | [integer] | Maximum number of terms to which the query expands for fuzzy matching. Defaults to 50.
23+
quote_analyzer | [keyword] | Analyzer used to convert quoted text in the query string into tokens.
24+
allow_wildcard | [boolean] | If true, the query attempts to analyze wildcard terms in the query string.
25+
boost | [float] | Floating point number used to decrease or increase the relevance scores of the query.
26+
quote_field_suffix | [keyword] | Suffix appended to quoted text in the query string.
27+
enable_position_increments | [boolean] | If true, enable position increments in queries constructed from a query_string search. Defaults to true.
28+
fields | [keyword] | Array of fields to search. Supports wildcards (*).
29+
|===

docs/reference/query-languages/esql/kibana/definition/functions/qstr.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,32 @@ public final class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStr
6161
public static final MultiMatchQueryBuilder.Type DEFAULT_TYPE = MultiMatchQueryBuilder.Type.BEST_FIELDS;
6262
public static final boolean DEFAULT_FUZZY_TRANSPOSITIONS = FuzzyQuery.defaultTranspositions;
6363

64-
private static final ParseField QUERY_FIELD = new ParseField("query");
65-
private static final ParseField FIELDS_FIELD = new ParseField("fields");
66-
private static final ParseField DEFAULT_FIELD_FIELD = new ParseField("default_field");
67-
private static final ParseField DEFAULT_OPERATOR_FIELD = new ParseField("default_operator");
68-
private static final ParseField ANALYZER_FIELD = new ParseField("analyzer");
69-
private static final ParseField QUOTE_ANALYZER_FIELD = new ParseField("quote_analyzer");
70-
private static final ParseField ALLOW_LEADING_WILDCARD_FIELD = new ParseField("allow_leading_wildcard");
71-
private static final ParseField MAX_DETERMINIZED_STATES_FIELD = new ParseField("max_determinized_states");
72-
private static final ParseField ENABLE_POSITION_INCREMENTS_FIELD = new ParseField("enable_position_increments");
73-
private static final ParseField ESCAPE_FIELD = new ParseField("escape");
74-
private static final ParseField FUZZY_PREFIX_LENGTH_FIELD = new ParseField("fuzzy_prefix_length");
75-
private static final ParseField FUZZY_MAX_EXPANSIONS_FIELD = new ParseField("fuzzy_max_expansions");
76-
private static final ParseField FUZZY_REWRITE_FIELD = new ParseField("fuzzy_rewrite");
77-
private static final ParseField PHRASE_SLOP_FIELD = new ParseField("phrase_slop");
78-
private static final ParseField TIE_BREAKER_FIELD = new ParseField("tie_breaker");
79-
private static final ParseField ANALYZE_WILDCARD_FIELD = new ParseField("analyze_wildcard");
80-
private static final ParseField REWRITE_FIELD = new ParseField("rewrite");
81-
private static final ParseField MINIMUM_SHOULD_MATCH_FIELD = new ParseField("minimum_should_match");
82-
private static final ParseField QUOTE_FIELD_SUFFIX_FIELD = new ParseField("quote_field_suffix");
83-
private static final ParseField LENIENT_FIELD = new ParseField("lenient");
84-
private static final ParseField TIME_ZONE_FIELD = new ParseField("time_zone");
85-
private static final ParseField TYPE_FIELD = new ParseField("type");
86-
private static final ParseField GENERATE_SYNONYMS_PHRASE_QUERY = new ParseField("auto_generate_synonyms_phrase_query");
87-
private static final ParseField FUZZY_TRANSPOSITIONS_FIELD = new ParseField("fuzzy_transpositions");
64+
public static final ParseField QUERY_FIELD = new ParseField("query");
65+
public static final ParseField BOOST_FIELD = new ParseField("boost");
66+
public static final ParseField FIELDS_FIELD = new ParseField("fields");
67+
public static final ParseField DEFAULT_FIELD_FIELD = new ParseField("default_field");
68+
public static final ParseField DEFAULT_OPERATOR_FIELD = new ParseField("default_operator");
69+
public static final ParseField ANALYZER_FIELD = new ParseField("analyzer");
70+
public static final ParseField QUOTE_ANALYZER_FIELD = new ParseField("quote_analyzer");
71+
public static final ParseField ALLOW_LEADING_WILDCARD_FIELD = new ParseField("allow_leading_wildcard");
72+
public static final ParseField MAX_DETERMINIZED_STATES_FIELD = new ParseField("max_determinized_states");
73+
public static final ParseField ENABLE_POSITION_INCREMENTS_FIELD = new ParseField("enable_position_increments");
74+
public static final ParseField ESCAPE_FIELD = new ParseField("escape");
75+
public static final ParseField FUZZINESS_FIELD = new ParseField("fuzziness");
76+
public static final ParseField FUZZY_PREFIX_LENGTH_FIELD = new ParseField("fuzzy_prefix_length");
77+
public static final ParseField FUZZY_MAX_EXPANSIONS_FIELD = new ParseField("fuzzy_max_expansions");
78+
public static final ParseField FUZZY_REWRITE_FIELD = new ParseField("fuzzy_rewrite");
79+
public static final ParseField PHRASE_SLOP_FIELD = new ParseField("phrase_slop");
80+
public static final ParseField TIE_BREAKER_FIELD = new ParseField("tie_breaker");
81+
public static final ParseField ANALYZE_WILDCARD_FIELD = new ParseField("analyze_wildcard");
82+
public static final ParseField REWRITE_FIELD = new ParseField("rewrite");
83+
public static final ParseField MINIMUM_SHOULD_MATCH_FIELD = new ParseField("minimum_should_match");
84+
public static final ParseField QUOTE_FIELD_SUFFIX_FIELD = new ParseField("quote_field_suffix");
85+
public static final ParseField LENIENT_FIELD = new ParseField("lenient");
86+
public static final ParseField TIME_ZONE_FIELD = new ParseField("time_zone");
87+
public static final ParseField TYPE_FIELD = new ParseField("type");
88+
public static final ParseField GENERATE_SYNONYMS_PHRASE_QUERY = new ParseField("auto_generate_synonyms_phrase_query");
89+
public static final ParseField FUZZY_TRANSPOSITIONS_FIELD = new ParseField("fuzzy_transpositions");
8890

8991
private final String queryString;
9092

0 commit comments

Comments
 (0)