-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Ensure integer sorts are rewritten to long sorts for BWC indexes #139293
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
Merged
elasticsearchmachine
merged 8 commits into
elastic:main
from
romseygeek:bug/sort-rewrite-int-to-long
Dec 11, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f680d10
Ensure integer sorts are rewritten to long sorts for backwards compat…
romseygeek b718f14
unmute
romseygeek 23f11e6
spotless
romseygeek e220c86
Handle STRING null missing value
romseygeek 26b69ac
edge cases
romseygeek 576487d
[CI] Auto commit changes from spotless
3c49fb9
Update docs/changelog/139293.yaml
romseygeek 8fb71c6
Merge branch 'main' into bug/sort-rewrite-int-to-long
romseygeek 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
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,7 @@ | ||
| pr: 139293 | ||
| summary: Ensure integer sorts are rewritten to long sorts for BWC indexes | ||
| area: Search | ||
| type: bug | ||
| issues: | ||
| - 139127 | ||
| - 139128 |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,9 @@ | |
| import org.apache.lucene.tests.index.RandomIndexWriter; | ||
| import org.apache.lucene.tests.search.AssertingIndexSearcher; | ||
| import org.apache.lucene.util.BytesRef; | ||
| import org.elasticsearch.common.lucene.Lucene; | ||
| import org.elasticsearch.index.IndexVersion; | ||
| import org.elasticsearch.index.IndexVersions; | ||
| import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource; | ||
| import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; | ||
| import org.elasticsearch.index.mapper.DateFieldMapper; | ||
|
|
@@ -46,6 +49,7 @@ | |
| import org.elasticsearch.search.MultiValueMode; | ||
| import org.elasticsearch.search.SearchSortValuesAndFormats; | ||
| import org.elasticsearch.search.builder.SearchSourceBuilder; | ||
| import org.elasticsearch.test.index.IndexVersionUtils; | ||
| import org.elasticsearch.xcontent.XContentParseException; | ||
| import org.elasticsearch.xcontent.XContentParser; | ||
| import org.elasticsearch.xcontent.json.JsonXContent; | ||
|
|
@@ -684,4 +688,39 @@ public void testIsBottomSortShardDisjoint() throws Exception { | |
| protected FieldSortBuilder fromXContent(XContentParser parser, String fieldName) throws IOException { | ||
| return FieldSortBuilder.fromXContent(parser, fieldName); | ||
| } | ||
|
|
||
| public void testIntRewritesToLong() throws IOException { | ||
|
Contributor
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. very nice test! |
||
| assertIntegerSortRewrite( | ||
| IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.INDEX_INT_SORT_INT_TYPE_8_19), | ||
| SortField.Type.LONG | ||
| ); | ||
| assertIntegerSortRewrite( | ||
| IndexVersionUtils.randomVersionBetween( | ||
| random(), | ||
| IndexVersions.INDEX_INT_SORT_INT_TYPE_8_19, | ||
| IndexVersionUtils.getPreviousVersion(IndexVersions.UPGRADE_TO_LUCENE_10_0_0) | ||
| ), | ||
| SortField.Type.INT | ||
| ); | ||
| assertIntegerSortRewrite( | ||
| IndexVersionUtils.randomVersionBetween( | ||
| random(), | ||
| IndexVersions.UPGRADE_TO_LUCENE_10_0_0, | ||
| IndexVersionUtils.getPreviousVersion(IndexVersions.INDEX_INT_SORT_INT_TYPE) | ||
| ), | ||
| SortField.Type.LONG | ||
| ); | ||
| assertIntegerSortRewrite( | ||
| IndexVersionUtils.randomVersionBetween(random(), IndexVersions.INDEX_INT_SORT_INT_TYPE, IndexVersion.current()), | ||
| SortField.Type.INT | ||
| ); | ||
| assertIntegerSortRewrite(IndexVersion.current(), SortField.Type.INT); | ||
| } | ||
|
|
||
| private void assertIntegerSortRewrite(IndexVersion version, SortField.Type expectedType) throws IOException { | ||
| FieldSortBuilder builder = new FieldSortBuilder("custom-integer"); | ||
| SortFieldAndFormat sff = builder.build(createMockSearchExecutionContext(version)); | ||
| SortField sf = Lucene.rewriteMergeSortField(sff.field()); | ||
| assertThat(sf.getType(), equalTo(expectedType)); | ||
| } | ||
| } | ||
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.
For my education, under what condition index sort is not instance of SortedNumericSortField?
Is it something new?
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.
Index sorts are always SortedNumericSortField instances, but query-time sorts now generally use custom comparators to pick up some performance improvements that are not in a released lucene version, so they are plain SortField instances.