-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add support for Elastic Search _shard_doc equivalent #18924
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
base: main
Are you sure you want to change the base?
Add support for Elastic Search _shard_doc equivalent #18924
Conversation
- Implements ShardDocSortBuilder + comparator - TODO: Add unit + integ tests - Registers in SearchModule Signed-off-by: Lamine Idjeraoui <[email protected]>
Signed-off-by: Lamine Idjeraoui <[email protected]>
❕ Gradle check result for 7199347: UNSTABLE Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #18924 +/- ##
============================================
+ Coverage 72.81% 72.95% +0.14%
- Complexity 69801 69925 +124
============================================
Files 5674 5676 +2
Lines 320850 320935 +85
Branches 46383 46398 +15
============================================
+ Hits 233638 234153 +515
+ Misses 68264 67842 -422
+ Partials 18948 18940 -8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@laminelam can we add any microbenchmark for it? |
❌ Gradle check result for f7d8f73: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
rest-api-spec/src/main/resources/rest-api-spec/test/search/95_search_after_shard_doc.yml
Show resolved
Hide resolved
Signed-off-by: Lamine Idjeraoui <[email protected]>
❌ Gradle check result for 9467d06: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
...src/internalClusterTest/java/org/opensearch/search/sort/ShardDocFieldComparatorSourceIT.java
Outdated
Show resolved
Hide resolved
❌ Gradle check result for a719fb7: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
❌ Gradle check result for a719fb7: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Thanks @laminelam, this PR is very close to merge, but seems the code test coverage is low, could you add more some unit tests? |
Thanks @laminelam , we are preparing the new release version (3.3.0) which the planned code freeze is Sep 30. Do you have a chance to fix the test coverage check ASAP? |
Hi @LantaoJin & @gaobinlong |
Hi |
add more test cases Signed-off-by: Lamine Idjeraoui <[email protected]>
❌ Gradle check result for 60f438d: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
@laminelam, will all PIT search requests add an implicit Example 1:
will sort by
Example 2
will sort by
|
if (sb instanceof FieldSortBuilder) { | ||
return ShardDocSortBuilder.NAME.equals(((FieldSortBuilder) sb).getFieldName()); | ||
} |
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.
This logic is never used because we are not allowed to create a FieldSortBuilder("_shard_doc")
. I got this exception if I create a FieldSortBuilder("_shard_doc"):
Caused by: org.opensearch.index.query.QueryShardException: No mapping found for [_shard_doc] in order to sort on
at org.opensearch.search.sort.FieldSortBuilder.resolveUnmappedType(FieldSortBuilder.java:571) ~[opensearch-3.3.0-SNAPSHOT.jar:3.3.0-SNAPSHOT]
at org.opensearch.search.sort.FieldSortBuilder.build(FieldSortBuilder.java:418) ~[opensearch-3.3.0-SNAPSHOT.jar:3.3.0-SNAPSHOT]
at org.opensearch.search.sort.SortBuilder.buildSort(SortBuilder.java:168) ~[opensearch-3.3.0-SNAPSHOT.jar:3.3.0-SNAPSHOT]
To fix it, we need to update the SearchSourceBuilder.sort(String)
OpenSearch/server/src/main/java/org/opensearch/search/builder/SearchSourceBuilder.java
Lines 590 to 595 in 5e6ee97
public SearchSourceBuilder sort(String name) { | |
if (name.equals(ScoreSortBuilder.NAME)) { | |
return sort(SortBuilders.scoreSort()); | |
} | |
return sort(SortBuilders.fieldSort(name)); | |
} |
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.
Hi @LantaoJin
I am not able to replicate the issue.
new FieldSortBuilder(ShardDocSortBuilder.NAME).order(SortOrder.ASC).build(context)
is not throwing any exception for me
wondering if we are testing on the same code
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.
This exception was thrown by fcalling SortBuilders.fieldSort("_shard_doc")
to build a source builder first then run client.search(request)
. Not a blocker IMO, I could call SortBuilders.shardDocSort()
.
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.
Oh ok I get it now. Actually this will not work and it's not the correct way of instantiating a ShardDocSortBuilder, because shard_doc is NOT a real field, it's a kind of pseudo field built on the fly, in the same way score
is not.
SortBuilders.fieldSort("fieldName")
is for real fields.
There is another method for shard_doc which is SortBuilders.shardDocSort()
In the same you would call scoreSort() for score, scriptSort() for script sort or geoDistanceSort
for geoDistance...
SearchRequest searchRequest = new SearchRequest().source( | ||
new SearchSourceBuilder().pointInTimeBuilder(new PointInTimeBuilder("id")) | ||
.sort(new FieldSortBuilder(ShardDocSortBuilder.NAME).order(SortOrder.ASC)) | ||
); | ||
ActionRequestValidationException e = searchRequest.validate(); | ||
assertNull(e); |
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.
Have you try new FieldSortBuilder(ShardDocSortBuilder.NAME).order(SortOrder.ASC).build()
? it will fail with
"No mapping found for [" + fieldName + "] in order to sort on"
Thought do it, actually did it and reverted it back, because I am little bit hesitant to implicitly tie a stable proven feature (PIT) to a newly introduced one (shard_doc sorting) in a single PR. I am thinking we better give the user the option to use PIT without shard_doc and at some point we can make it implicit in a separate PR. I think this is a safest path to avoid breaking anything and also make it backwards compatible. What are your thoughts? |
Make sense, LGTM. |
New feature or enhancement won't be backported to 2.19, only bug fix and security issue fix PR can be backported. |
❕ Gradle check result for 60f438d: UNSTABLE Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure. |
Implements a new ShardDocSortBuilder and ShardDocFieldComparatorSource to allow sorting by shard id and global doc id as a tie-breaker.
Resolves 17064
Check List
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.