Skip to content

Commit

Permalink
Fix multi-value sort for unsigned long (#16732) (#16994)
Browse files Browse the repository at this point in the history
* Fix multi-value sort for unsigned long



* Add initial rest-api-spec tests



* add more rest tests



* fix



* fix



* Extend MultiValueMode with dedicated support of unsigned_long doc values



* Add CHANGELOG.md, minor cleanups



* Correct the license headers



* Correct the @publicapi version



* Replace SingletonSortedNumericUnsignedLongValues with LongToSortedNumericUnsignedLongValues (as per review comments)



---------




(cherry picked from commit f6dc4a6)

Signed-off-by: panguixin <[email protected]>
Signed-off-by: Andriy Redko <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Andriy Redko <[email protected]>
  • Loading branch information
3 people authored Jan 10, 2025
1 parent da323e5 commit 2ed6c91
Show file tree
Hide file tree
Showing 9 changed files with 1,126 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix _list/shards API failing when closed indices are present ([#16606](https://github.com/opensearch-project/OpenSearch/pull/16606))
- Always use `constant_score` query for `match_only_text` field ([#16964](https://github.com/opensearch-project/OpenSearch/pull/16964))
- Fix Shallow copy snapshot failures on closed index ([#16868](https://github.com/opensearch-project/OpenSearch/pull/16868))
- Fix multi-value sort for unsigned long ([#16732](https://github.com/opensearch-project/OpenSearch/pull/16732))

### Security

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
setup:
- do:
indices.create:
index: double_sort
body:
settings:
number_of_shards: 3
number_of_replicas: 0
mappings:
properties:
field:
type: double

---
"test sorting against double only fields":

- do:
bulk:
refresh: true
body:
- '{ "index" : { "_index" : "double_sort", "_id" : "1" } }'
- '{"field" : [ 900719925474099.1, 1.1 ] }'
- '{ "index" : { "_index" : "double_sort", "_id" : "2" } }'
- '{"field" : [ 900719925474099.2, 900719925474099.3 ] }'
- '{ "index" : { "_index" : "double_sort", "_id" : "3" } }'
- '{"field" : [ 450359962737049.4, 3.5, 4.6 ] }'
- '{ "index" : { "_index" : "double_sort", "_id" : "4" } }'
- '{"field" : [ 450359962737049.7, 5.8, -1.9, -2.0 ] }'

- do:
search:
index: double_sort
body:
size: 5
sort: [{ field: { mode: max, order: desc } } ]
- match: {hits.total.value: 4 }
- length: {hits.hits: 4 }
- match: { hits.hits.0._index: double_sort }
- match: { hits.hits.0._source.field: [ 900719925474099.2, 900719925474099.2 ] }
- match: { hits.hits.0.sort.0: 900719925474099.2 }
- match: { hits.hits.1._source.field: [ 900719925474099.1, 1.1 ] }
- match: { hits.hits.1.sort.0: 900719925474099.1 }
- match: { hits.hits.2._source.field: [ 450359962737049.7, 5.8, -1.9, -2.0 ] }
- match: { hits.hits.2.sort.0: 450359962737049.7 }
- match: { hits.hits.3._source.field: [ 450359962737049.4, 3.5, 4.6 ] }
- match: { hits.hits.3.sort.0: 450359962737049.4 }

- do:
search:
index: double_sort
body:
size: 5
sort: [ { field: { mode: max, order: asc } } ]
- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- match: { hits.hits.0._index: double_sort }
- match: { hits.hits.0._source.field: [ 450359962737049.4, 3.5, 4.6 ] }
- match: { hits.hits.0.sort.0: 450359962737049.4 }
- match: { hits.hits.1._source.field: [ 450359962737049.7, 5.8, -1.9, -2.0 ] }
- match: { hits.hits.1.sort.0: 450359962737049.7 }
- match: { hits.hits.2._source.field: [ 900719925474099.1, 1.1 ] }
- match: { hits.hits.2.sort.0: 900719925474099.1 }
- match: { hits.hits.3._source.field: [ 900719925474099.2, 900719925474099.2 ] }
- match: { hits.hits.3.sort.0: 900719925474099.2 }

- do:
search:
index: double_sort
body:
size: 5
sort: [ { field: { mode: min, order: asc } } ]
- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- match: { hits.hits.0._index: double_sort }
- match: { hits.hits.0._source.field: [ 450359962737049.7, 5.8, -1.9, -2.0 ] }
- match: { hits.hits.0.sort: [ -2.0 ] }
- match: { hits.hits.1._source.field: [ 900719925474099.1, 1.1 ] }
- match: { hits.hits.1.sort.0: 1.1 }
- match: { hits.hits.2._source.field: [ 450359962737049.4, 3.5, 4.6 ] }
- match: { hits.hits.2.sort.0: 3.5 }
- match: { hits.hits.3._source.field: [ 900719925474099.2, 900719925474099.2 ] }
- match: { hits.hits.3.sort.0: 900719925474099.2 }

- do:
search:
index: double_sort
body:
size: 5
sort: [ { field: { mode: median, order: desc } } ]
- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- match: { hits.hits.0._index: double_sort }
- match: { hits.hits.0._source.field: [ 900719925474099.2, 900719925474099.2 ] }
- match: { hits.hits.0.sort.0: 900719925474099.2 }
- match: { hits.hits.1._source.field: [ 900719925474099.1, 1.1 ] }
- match: { hits.hits.1.sort.0: 450359962737050.1 }
- match: { hits.hits.2._source.field: [ 450359962737049.4, 3.5, 4.6 ] }
- match: { hits.hits.2.sort.0: 4.6 }
- match: { hits.hits.3._source.field: [ 450359962737049.7, 5.8, -1.9, -2.0 ] }
- match: { hits.hits.3.sort.0: 1.95 }

- do:
search:
index: double_sort
body:
size: 5
sort: [ { field: { mode: avg, order: asc } } ]
- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- match: { hits.hits.0._index: double_sort }
- match: { hits.hits.0._source.field: [ 450359962737049.7, 5.8, -1.9, -2.0 ] }
- match: { hits.hits.0.sort.0: 112589990684262.89 }
- match: { hits.hits.1._source.field: [ 450359962737049.4, 3.5, 4.6 ] }
- match: { hits.hits.1.sort.0: 150119987579019.16 }
- match: { hits.hits.2._source.field: [ 900719925474099.1, 1.1 ] }
- match: { hits.hits.2.sort.0: 450359962737050.1 }
- match: { hits.hits.3._source.field: [ 900719925474099.2, 900719925474099.2 ] }
- match: { hits.hits.3.sort.0: 900719925474099.2 }

- do:
search:
index: double_sort
body:
size: 5
sort: [ { field: { mode: sum, order: desc } } ]
- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- match: { hits.hits.0._index: double_sort }
- match: { hits.hits.0._source.field: [ 900719925474099.2, 900719925474099.2 ] }
- match: { hits.hits.0.sort.0: 1801439850948198.5 }
- match: { hits.hits.1._source.field: [ 900719925474099.1, 1.1 ] }
- match: { hits.hits.1.sort.0: 900719925474100.2 }
- match: { hits.hits.2._source.field: [ 450359962737049.4, 3.5, 4.6 ] }
- match: { hits.hits.2.sort.0: 450359962737057.5 }
- match: { hits.hits.3._source.field: [ 450359962737049.7, 5.8, -1.9, -2.0 ] }
- match: { hits.hits.3.sort.0: 450359962737051.56 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
setup:
- do:
indices.create:
index: long_sort
body:
settings:
number_of_shards: 3
number_of_replicas: 0
mappings:
properties:
field:
type: long

---
"test sorting against long only fields":

- do:
bulk:
refresh: true
body:
- '{ "index" : { "_index" : "long_sort", "_id" : "1" } }'
- '{"field" : [ 9223372036854775807, 1 ] }'
- '{ "index" : { "_index" : "long_sort", "_id" : "2" } }'
- '{"field" : [ 922337203685477777, 2 ] }'
- '{ "index" : { "_index" : "long_sort", "_id" : "3" } }'
- '{"field" : [ 2147483647, 3, 4 ] }'
- '{ "index" : { "_index" : "long_sort", "_id" : "4" } }'
- '{"field" : [ 2147483648, 5, -1, -2 ] }'

- do:
search:
index: long_sort
body:
size: 5
sort: [{ field: { mode: max, order: desc } } ]
- match: {hits.total.value: 4 }
- length: {hits.hits: 4 }
- match: { hits.hits.0._index: long_sort }
- match: { hits.hits.0._source.field: [ 9223372036854775807, 1 ] }
- match: { hits.hits.0.sort.0: 9223372036854775807 }
- match: { hits.hits.1._source.field: [ 922337203685477777, 2 ] }
- match: { hits.hits.1.sort.0: 922337203685477777 }
- match: { hits.hits.2._source.field: [ 2147483648, 5, -1, -2 ] }
- match: { hits.hits.2.sort.0: 2147483648 }
- match: { hits.hits.3._source.field: [ 2147483647, 3, 4 ] }
- match: { hits.hits.3.sort.0: 2147483647 }

- do:
search:
index: long_sort
body:
size: 5
sort: [ { field: { mode: max, order: asc } } ]
- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- match: { hits.hits.0._index: long_sort }
- match: { hits.hits.0._source.field: [ 2147483647, 3, 4 ] }
- match: { hits.hits.0.sort.0: 2147483647 }
- match: { hits.hits.1._source.field: [ 2147483648, 5, -1, -2 ] }
- match: { hits.hits.1.sort.0: 2147483648 }
- match: { hits.hits.2._source.field: [ 922337203685477777, 2 ] }
- match: { hits.hits.2.sort.0: 922337203685477777 }
- match: { hits.hits.3._source.field: [ 9223372036854775807, 1 ] }
- match: { hits.hits.3.sort.0: 9223372036854775807 }


- do:
search:
index: long_sort
body:
size: 5
sort: [{ field: { mode: min, order: desc } } ]
- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- match: { hits.hits.0._index: long_sort }
- match: { hits.hits.0._source.field: [ 2147483647, 3, 4 ] }
- match: { hits.hits.0.sort.0: 3 }
- match: { hits.hits.1._source.field: [ 922337203685477777, 2 ] }
- match: { hits.hits.1.sort.0: 2 }
- match: { hits.hits.2._source.field: [ 9223372036854775807, 1 ] }
- match: { hits.hits.2.sort.0: 1 }
- match: { hits.hits.3._source.field: [ 2147483648, 5, -1, -2 ] }
- match: { hits.hits.3.sort: [ -2 ] }

- do:
search:
index: long_sort
body:
size: 5
sort: [ { field: { mode: median, order: asc } } ]
- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- match: { hits.hits.0._index: long_sort }
- match: { hits.hits.0._source.field: [ 2147483648, 5, -1, -2 ] }
- match: { hits.hits.0.sort.0: 2 }
- match: { hits.hits.1._source.field: [ 2147483647, 3, 4 ] }
- match: { hits.hits.1.sort.0: 4 }
- match: { hits.hits.2._source.field: [ 922337203685477777, 2 ] }
- match: { hits.hits.2.sort.0: 461168601842738880 }
- match: { hits.hits.3._source.field: [ 9223372036854775807, 1 ] }
- match: { hits.hits.3.sort.0: 4611686018427387904 }

- do:
search:
index: long_sort
body:
size: 5
sort: [ { field: { mode: avg, order: desc } } ]
- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- match: { hits.hits.0._index: long_sort }
- match: { hits.hits.0._source.field: [ 922337203685477777, 2 ] }
- match: { hits.hits.0.sort.0: 461168601842738880 }
- match: { hits.hits.1._source.field: [ 2147483647, 3, 4 ] }
- match: { hits.hits.1.sort.0: 715827885 }
- match: { hits.hits.2._source.field: [ 2147483648, 5, -1, -2 ] }
- match: { hits.hits.2.sort.0: 536870913 }
- match: { hits.hits.3._source.field: [ 9223372036854775807, 1 ] }
- match: { hits.hits.3.sort: [ -4611686018427387904 ] }

- do:
search:
index: long_sort
body:
size: 5
sort: [ { field: { mode: sum, order: asc } } ]
- match: { hits.total.value: 4 }
- length: { hits.hits: 4 }
- match: { hits.hits.0._index: long_sort }
- match: { hits.hits.0._source.field: [ 9223372036854775807, 1 ] }
- match: { hits.hits.0.sort: [ -9223372036854775808 ] }
- match: { hits.hits.1._source.field: [ 2147483648, 5, -1, -2 ] }
- match: { hits.hits.1.sort.0: 2147483650 }
- match: { hits.hits.2._source.field: [ 2147483647, 3, 4 ] }
- match: { hits.hits.2.sort.0: 2147483654 }
- match: { hits.hits.3._source.field: [ 922337203685477777, 2 ] }
- match: { hits.hits.3.sort.0: 922337203685477779 }
Loading

0 comments on commit 2ed6c91

Please sign in to comment.