Skip to content

Commit

Permalink
Fixing SortField comparison to use equals instead of reference equality
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
reta committed Mar 30, 2023
1 parent 4859e15 commit 02fa61b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"search across indices with mixed long and double numeric types":
- skip:
version: " - 2.6.99"
reason: relies on numeric sort optimization that landed in 2.7.0 only

- do:
indices.create:
index: test_1
body:
mappings:
properties:
counter:
type: long

- do:
indices.create:
index: test_2
body:
mappings:
properties:
counter:
type: double
- do:
bulk:
refresh: true
body:
- index:
_index: test_1
- counter: 223372036854775800
- index:
_index: test_2
- counter: 1223372036854775800.23
- index:
_index: test_2
- counter: 184.4

- do:
search:
index: test_*
rest_total_hits_as_int: true
body:
sort: [{ counter: desc }]
- match: { hits.total: 3 }
- length: { hits.hits: 3 }
- match: { hits.hits.0._index: test_2 }
- match: { hits.hits.0._source.counter: 1223372036854775800.23 }
- match: { hits.hits.0.sort: [1223372036854775800.23] }
- match: { hits.hits.1._index: test_1 }
- match: { hits.hits.1._source.counter: 223372036854775800 }
- match: { hits.hits.1.sort: [223372036854775800] }

- do:
search:
index: test_*
rest_total_hits_as_int: true
body:
sort: [{ counter: asc }]
- match: { hits.total: 3 }
- length: { hits.hits: 3 }
- match: { hits.hits.0._index: test_2 }
- match: { hits.hits.0._source.counter: 184.4 }
- match: { hits.hits.0.sort: [184.4] }
- match: { hits.hits.1._index: test_1 }
- match: { hits.hits.1._source.counter: 223372036854775800 }
- match: { hits.hits.1.sort: [223372036854775800] }
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ private static Sort createSort(TopFieldDocs[] topFieldDocs) {
*/
private static boolean isSortWideningRequired(TopFieldDocs[] topFieldDocs, int sortFieldindex) {
for (int i = 0; i < topFieldDocs.length - 1; i++) {
if (topFieldDocs[i].fields[sortFieldindex] != topFieldDocs[i + 1].fields[sortFieldindex]) {
if (!topFieldDocs[i].fields[sortFieldindex].equals(topFieldDocs[i + 1].fields[sortFieldindex])) {
return true;
}
}
Expand Down

0 comments on commit 02fa61b

Please sign in to comment.