Skip to content
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

ES|QL Search: allow WHERE with text predicates #110132

Merged
merged 5 commits into from
Jun 26, 2024

Conversation

ioanatia
Copy link
Contributor

When WHERE is used in the search context of the SEARCH command it can now receive the expressions using MATCH.

POST _query
{
  "query": """
  SEARCH search-movies [
    | WHERE MATCH(Title, "hobbit") AND imdbRating > 8.0
  ]
  | KEEP Title, _score
  """
}

This will apply a boolean query with a filter clause - the returned results will have scores equal to zero, since no ranking is happening.

The grammar has been simplified, so for the moment WHERE and RANK allow the same type of expressions when used in the SEARCH context.

var actualLuceneQuery = as(fieldExtract.child(), EsQueryExec.class).query();

var expectedLuceneQuery = new BoolQueryBuilder().filter(
new BoolQueryBuilder().must(new MatchQueryBuilder("first_name", "Meg")).must(new MatchQueryBuilder("last_name", "Ryan"))
Copy link
Contributor Author

@ioanatia ioanatia Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an interesting behaviour that we can follow up on separately.
I would expect that we just have a bool query with two filter clauses:

 var expectedLuceneQuery =  new BoolQueryBuilder().filter(new MatchQueryBuilder("first_name", "Meg")).filter(new MatchQueryBuilder("last_name", "Ryan"))

instead we are using must clauses which comes from how the PushFiltersToSource forms the query, specifically here:

Query queryDSL = TRANSLATOR_HANDLER.asQuery(Predicates.combineAnd(pushable));

We can see that this behaviour happens with FROM too, take this test query:

var plan = plannerOptimizer.plan("""
from test
| where salary > 1000
| stats c = count(salary)
""", IS_SV_STATS);

the filters are pushed as must clauses:

I think maybe they should be pushed as filter instead since must clauses add to the score which for filters we don't care about?

EDIT: maybe this is okay since we wrap everything in a constant score anyway for the FROM command and Lucene optimizations should kick in?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question. It works ok, by I also suspect that filter would be more appropriate here.

@ioanatia ioanatia marked this pull request as ready for review June 25, 2024 15:19
@elasticsearchmachine elasticsearchmachine added the needs:triage Requires assignment of a team area label label Jun 25, 2024
@ioanatia ioanatia added :Search Relevance/Percolator Reverse search: find queries that match a document :Search/Search Search-related issues that do not fall into other categories and removed :Search Relevance/Percolator Reverse search: find queries that match a document labels Jun 25, 2024
@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Jun 25, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Jun 25, 2024
@ioanatia
Copy link
Contributor Author

@elasticsearchmachine test this please

@ChrisHegarty
Copy link
Contributor

@elasticmachine update branch

@ChrisHegarty
Copy link
Contributor

@elasticmachine update branch

Copy link
Contributor

@ChrisHegarty ChrisHegarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ioanatia ioanatia merged commit 4478e7a into elastic:esql/search Jun 26, 2024
14 of 15 checks passed
@ioanatia ioanatia deleted the search_where_match branch June 26, 2024 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants