Skip to content

Commit

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

Signed-off-by: panguixin <panguixin@bytedance.com>

* Add initial rest-api-spec tests

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

* add more rest tests

Signed-off-by: panguixin <panguixin@bytedance.com>

* fix

Signed-off-by: panguixin <panguixin@bytedance.com>

* fix

Signed-off-by: panguixin <panguixin@bytedance.com>

* Extend MultiValueMode with dedicated support of unsigned_long doc values

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

* Add CHANGELOG.md, minor cleanups

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

* Correct the license headers

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

* Correct the @publicapi version

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

* Replace SingletonSortedNumericUnsignedLongValues with LongToSortedNumericUnsignedLongValues (as per review comments)

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

---------

Signed-off-by: panguixin <panguixin@bytedance.com>
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
Co-authored-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
2 people authored and meetvm committed Jan 16, 2025
1 parent 0fc7b6b commit 7bb7e29
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 @@ -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

0 comments on commit 7bb7e29

Please sign in to comment.