Skip to content
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

Fix multi-value sort for unsigned long #16732

Merged
merged 13 commits into from
Jan 10, 2025
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix remote shards balance ([#15335](https://github.com/opensearch-project/OpenSearch/pull/15335))
- 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
Loading