-
Notifications
You must be signed in to change notification settings - Fork 25.6k
ES|QL: Allow simplified full text search using text in where clause #135264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
timgrein
wants to merge
16
commits into
elastic:main
Choose a base branch
from
timgrein:esql-simpler-full-text-function
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f6c92f2
Allow simplified full text search using string in where condition
timgrein 0b07c3c
[CI] Update transport version definitions
d5e4666
Add grammar adjustments and regenerated sources
timgrein 388ee0f
Merge remote-tracking branch 'origin/esql-simpler-full-text-function'…
timgrein d136a0f
Add FullTextSearch marker class
timgrein 39c2af3
Replace FullTextSearch with MultiMatch in Analyzer
timgrein fcfeb58
ADd ReplaceSingleMultiMatchWithMatch optimizer rule
timgrein 8df6941
spotlessApply
timgrein 05808b5
Merge branch 'main' into esql-simpler-full-text-function
timgrein d936507
Regen Parser
timgrein ef5d45c
Remove one unnecessary test case in LogicalPlanOptimizerTests
timgrein 54a2cf5
Add tests for option passing and fix option key retrieval
timgrein 04be8e6
Remove addressed TODO
timgrein 8781763
Merge branch 'main' into esql-simpler-full-text-function
timgrein d434f7a
Regen parser
timgrein 2e7f334
Merge branch 'main' into esql-simpler-full-text-function
timgrein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
x-pack/plugin/esql/qa/testFixtures/src/main/resources/where-simple-full-text-search.csv-spec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| whereSimpleFullTextSearch | ||
| required_capability: multi_match_function | ||
| required_capability: match_function | ||
| from employees | where "Eberhardt" | keep emp_no, first_name; | ||
|
|
||
| emp_no:integer | first_name:keyword | ||
| 10013 | Eberhardt | ||
| ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...c/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextSearch.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.esql.expression.function.fulltext; | ||
|
|
||
| import org.elasticsearch.xpack.esql.core.expression.Expression; | ||
| import org.elasticsearch.xpack.esql.core.expression.UnresolvedStar; | ||
| import org.elasticsearch.xpack.esql.core.querydsl.query.Query; | ||
| import org.elasticsearch.xpack.esql.core.tree.Source; | ||
| import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates; | ||
| import org.elasticsearch.xpack.esql.planner.TranslatorHandler; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Marker class for simplified full-text search over all text fields in an index represented in ES|QL as: | ||
| * "FROM index | WHERE query" | ||
| * | ||
| * This will be resolved to {@link MultiMatch} over all text fields during the analysis phase. | ||
| */ | ||
| public class FullTextSearch extends MultiMatch { | ||
|
|
||
| public FullTextSearch(Source source, Expression query) { | ||
| super(source, query, List.of(new UnresolvedStar(source, null)), null); | ||
| } | ||
|
|
||
| @Override | ||
| protected Query translate(LucenePushdownPredicates pushdownPredicates, TranslatorHandler handler) { | ||
| throw new IllegalStateException("FullTextSearch function should be resolved to MULTI_MATCH before translation"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...rg/elasticsearch/xpack/esql/optimizer/rules/logical/ReplaceSingleMultiMatchWithMatch.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.esql.optimizer.rules.logical; | ||
|
|
||
| import org.elasticsearch.xpack.esql.core.expression.Expression; | ||
| import org.elasticsearch.xpack.esql.core.expression.Literal; | ||
| import org.elasticsearch.xpack.esql.core.expression.MapExpression; | ||
| import org.elasticsearch.xpack.esql.core.tree.Source; | ||
| import org.elasticsearch.xpack.esql.expression.function.fulltext.Match; | ||
| import org.elasticsearch.xpack.esql.expression.function.fulltext.MultiMatch; | ||
| import org.elasticsearch.xpack.esql.plan.logical.Filter; | ||
| import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.elasticsearch.xpack.esql.core.type.DataType.KEYWORD; | ||
|
|
||
| /** | ||
| * Replaces {@link MultiMatch} with {@link Match}, iff {@link MultiMatch} only specifies one text field. | ||
| * This enables matching on a single `semantic_text` field as {@link MultiMatch} doesn't work with `semantic_text`. | ||
| */ | ||
| public final class ReplaceSingleMultiMatchWithMatch extends OptimizerRules.OptimizerRule<Filter> { | ||
| @Override | ||
| protected LogicalPlan rule(Filter filter) { | ||
| Expression condition = filter.condition(); | ||
|
|
||
| if (condition instanceof MultiMatch multiMatch && multiMatch.fields().size() == 1) { | ||
| // MULTI_MATCH and MATCH have a subset of common options | ||
| Expression filteredOptions = filterOptionsForMatch(multiMatch.options()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will add a test making sure options are passed correctly from |
||
| Match match = new Match(Source.EMPTY, multiMatch.fields().getFirst(), multiMatch.query(), filteredOptions); | ||
|
|
||
| return new Filter(filter.source(), filter.child(), match); | ||
| } | ||
|
|
||
| return filter; | ||
| } | ||
|
|
||
| private Expression filterOptionsForMatch(Expression multiMatchOptions) { | ||
| if ((multiMatchOptions instanceof MapExpression) == false) { | ||
| return null; | ||
| } | ||
|
|
||
| MapExpression mapExpr = (MapExpression) multiMatchOptions; | ||
|
|
||
| // Filter the map entries to only include allowed options | ||
| List<Map.Entry<Expression, Expression>> filteredEntries = mapExpr.map().entrySet().stream().filter(entry -> { | ||
| if (entry.getKey() instanceof Literal literal && literal.dataType() == KEYWORD) { | ||
| String optionName = literal.value().toString(); | ||
| return Match.ALLOWED_OPTIONS.containsKey(optionName); | ||
| } | ||
| return false; | ||
| }).toList(); | ||
|
|
||
| // Return null if no valid options remain | ||
| if (filteredEntries.isEmpty()) { | ||
| return null; | ||
| } | ||
|
|
||
| List<Expression> entries = new ArrayList<>(); | ||
|
|
||
| filteredEntries.forEach(entry -> { | ||
| entries.add(entry.getKey()); | ||
| entries.add(entry.getValue()); | ||
| }); | ||
|
|
||
| return new MapExpression(multiMatchOptions.source(), entries); | ||
| } | ||
| } | ||
2 changes: 1 addition & 1 deletion
2
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParser.interp
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively we could check, if
MultiMatchcontains one field, which is an instance ofUnresolvedStarinstead of introducing a separate "marker class"FullTextSearch.