-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
#48475 Pure disjunctions should rewrite to a MatchNoneQueryBuilder #48557
Conversation
SivagurunathanV
commented
Oct 27, 2019
- Added Pure disjunctions should rewrite to a MatchNoneQueryBuilder when all instance matches MatchNoneQueryBuilder
- Added testcase for the same.
@SivagurunathanV we already rewrite |
@SivagurunathanV The linked issue is about optional clauses while your PR handles required clauses. If you don't understand how the issue should be addressed, please raise questions before opening a pull request. |
@SivagurunathanV Yes indeed. One important factor is that SHOULD clauses behave differently depending on whether there are any required (MUST or FILTER) clauses, so we will need to be carefull with this. |
@jpountz Thanks for the explanation. Based on my understanding, if the required clauses are empty and the optional clause is returning MatchNone, we can safely make an early termination. |
@SivagurunathanV Yes, if there are no required clauses and all SHOULD clauses rewrite to a MatchNoneQueryBuilder then the bool query can rewrite to a MatchNoneQueryBuilder. |
@jpountz Thanks. Added my changes to the PR. Please let me know if that works. |
Pinging @elastic/es-search (:Search/Search) |
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.
Thanks, the change looks good to me! I'll merge this PR next week.
@jpountz Can you merge this PR? |
Oops, thanks for the reminder, I'll merge soon. |
@elasticmachine ok to test |
@@ -417,12 +417,19 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws | |||
changed |= rewriteClauses(queryRewriteContext, mustNotClauses, newBuilder::mustNot); | |||
changed |= rewriteClauses(queryRewriteContext, filterClauses, newBuilder::filter); | |||
changed |= rewriteClauses(queryRewriteContext, shouldClauses, newBuilder::should); | |||
// early termination when must clause is empty and optional clauses is returning MatchNoneQueryBuilder | |||
if(mustClauses.size() == 0 && filterClauses.size() == 0 |
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.
Given test failures, I think the problem is that this rewrites empty boolean queries to a match_none, while this is currently treated as a match_all. We probably to do something like below, can you add a unit test for this case?
if(mustClauses.size() == 0 && filterClauses.size() == 0 | |
if (mustClauses.size() == 0 && filterClauses.size() == 0 && shouldClauses.size() > 0 |
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.
Thanks for the catch. I just updated the code. Let me know.
@jpountz I am not able to see the failed job logs in Jenkins, can you please help me here. what is the exact issue. Thanks |
@elasticmachine ok to test |
@SivagurunathanV The logs don't require authentication or anything, so you should be able to read them. Some tests were complaining that the matching documents were not the expected ones. |
user doesn't have permission to update head repository |
@SivagurunathanV Would you mind merging master into your branch? |
@jpountz Thanks for the help. I merged the master into my branch and all test passed :) |
@elasticmachine ok to test |
Thanks @SivagurunathanV ! |