-
Notifications
You must be signed in to change notification settings - Fork 132
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
Ensure consistent filter query in KNNQueryBuilder across multiple shards #2359
Conversation
Signed-off-by: Sahil Buddharaju <[email protected]>
Signed-off-by: Sahil Buddharaju <[email protected]>
Signed-off-by: Sahil Buddharaju <[email protected]>
2d874cb
to
bdd753d
Compare
Hi @buddharajusahil thanks for creating the PR. can you please add some details why above thing is impacting the queries? |
Thanks for fix @buddharajusahil - seems this is consistent with how bool query does it - https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/java/org/opensearch/index/query/BoolQueryBuilder.java#L367-L401. For the test cases, did you confirm that they fail before change is introduced and not after just to validate the fix? |
Signed-off-by: Sahil Buddharaju <[email protected]>
4124d06
to
84e9c74
Compare
@jmazanec15 Hi Jack, I decided to add new IT tests, as martin's were moreso checking if unknown filters were being properly written. With these new IT's, they are able to properly fail with the old rewrite, and succeed with the change. |
src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java
Outdated
Show resolved
Hide resolved
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.
Should we make the fields in KNNQueryBuilder final?
@buddharajusahil This was a great find. Thanks for the deep-dive. |
not sure how making things final will help here? Final helps only in case when references are changing. Do you think any other reason here for making things final |
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.
@buddharajusahil
Code looks good to me. Please fix the comments added by @shatejas , as I have no more extra comments apart from his comments
Signed-off-by: Sahil Buddharaju <[email protected]>
30734d7
to
17d7a24
Compare
Signed-off-by: Sahil Buddharaju <[email protected]>
22b27dc
to
d6a2ebb
Compare
@navneet1v here the |
src/test/java/org/opensearch/knn/index/query/KNNQueryBuilderTests.java
Outdated
Show resolved
Hide resolved
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.
Looks good overall
Signed-off-by: Sahil Buddharaju <[email protected]>
85f362d
to
9a03e20
Compare
Signed-off-by: Sahil Buddharaju <[email protected]>
4986cae
to
887af64
Compare
Signed-off-by: sahil <[email protected]>
…rds (#2359) * Changed filter logic Signed-off-by: Sahil Buddharaju <[email protected]> * spotless Signed-off-by: Sahil Buddharaju <[email protected]> * Changelog Signed-off-by: Sahil Buddharaju <[email protected]> * Added unit tests to test multi shard filters Signed-off-by: Sahil Buddharaju <[email protected]> * Changed unit tests and used builder instead of constructor Signed-off-by: Sahil Buddharaju <[email protected]> * Spotless apply Signed-off-by: Sahil Buddharaju <[email protected]> * slight unit test adjustment Signed-off-by: Sahil Buddharaju <[email protected]> * changelog Signed-off-by: Sahil Buddharaju <[email protected]> --------- Signed-off-by: Sahil Buddharaju <[email protected]> Signed-off-by: sahil <[email protected]> Co-authored-by: Sahil Buddharaju <[email protected]> (cherry picked from commit c969f1d)
…rds (opensearch-project#2359) * Changed filter logic Signed-off-by: Sahil Buddharaju <[email protected]> * spotless Signed-off-by: Sahil Buddharaju <[email protected]> * Changelog Signed-off-by: Sahil Buddharaju <[email protected]> * Added unit tests to test multi shard filters Signed-off-by: Sahil Buddharaju <[email protected]> * Changed unit tests and used builder instead of constructor Signed-off-by: Sahil Buddharaju <[email protected]> * Spotless apply Signed-off-by: Sahil Buddharaju <[email protected]> * slight unit test adjustment Signed-off-by: Sahil Buddharaju <[email protected]> * changelog Signed-off-by: Sahil Buddharaju <[email protected]> --------- Signed-off-by: Sahil Buddharaju <[email protected]> Signed-off-by: sahil <[email protected]> Co-authored-by: Sahil Buddharaju <[email protected]>
…rds (opensearch-project#2359) * Changed filter logic Signed-off-by: Sahil Buddharaju <[email protected]> * spotless Signed-off-by: Sahil Buddharaju <[email protected]> * Changelog Signed-off-by: Sahil Buddharaju <[email protected]> * Added unit tests to test multi shard filters Signed-off-by: Sahil Buddharaju <[email protected]> * Changed unit tests and used builder instead of constructor Signed-off-by: Sahil Buddharaju <[email protected]> * Spotless apply Signed-off-by: Sahil Buddharaju <[email protected]> * slight unit test adjustment Signed-off-by: Sahil Buddharaju <[email protected]> * changelog Signed-off-by: Sahil Buddharaju <[email protected]> --------- Signed-off-by: Sahil Buddharaju <[email protected]> Signed-off-by: sahil <[email protected]> Co-authored-by: Sahil Buddharaju <[email protected]>
Description
This change is to resolve issue #2339. This PR addresses it by changing some flawed logic in the rewrite function of the KNNQueryBuilder class, introduced in this PR: #1874. What was happening before was the filter for the KNNQueryBuilder object was being rewritten upon contact with first shard, and since this instance is getting shared across all shards, other shards are using the rewritten filter from the first shard.
What this causes is, if shard id 0 has no documents and shard id 1 has 1 document, if query lands on shard 0, the filter is rewritten to return none, as shard id 0 has no documents, so the filter is adjusted. However, since we were changing the filter in the KNN query object, rather than creating a new rewritten object for shard 0, when the query lands on shard 1, the filter has been rewritten to return none from shard 0, so even though the document is on shard 1, we will return no hits.
Now it is changed so that the rewrite class returns a new KNNQueryBuilder with the rewritten filter per shard.
Related Issues
Resolves #2339
Check List
--signoff
.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.