Skip to content

Commit 2ed6c91

Browse files
opensearch-trigger-bot[bot]github-actions[bot]reta
authored
Fix multi-value sort for unsigned long (#16732) (#16994)
* 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 <panguixin@bytedance.com> Signed-off-by: Andriy Redko <andriy.redko@aiven.io> 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 <andriy.redko@aiven.io>
1 parent da323e5 commit 2ed6c91

File tree

9 files changed

+1126
-5
lines changed

9 files changed

+1126
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8181
- Fix _list/shards API failing when closed indices are present ([#16606](https://github.com/opensearch-project/OpenSearch/pull/16606))
8282
- Always use `constant_score` query for `match_only_text` field ([#16964](https://github.com/opensearch-project/OpenSearch/pull/16964))
8383
- Fix Shallow copy snapshot failures on closed index ([#16868](https://github.com/opensearch-project/OpenSearch/pull/16868))
84+
- Fix multi-value sort for unsigned long ([#16732](https://github.com/opensearch-project/OpenSearch/pull/16732))
8485

8586
### Security
8687

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
setup:
2+
- do:
3+
indices.create:
4+
index: double_sort
5+
body:
6+
settings:
7+
number_of_shards: 3
8+
number_of_replicas: 0
9+
mappings:
10+
properties:
11+
field:
12+
type: double
13+
14+
---
15+
"test sorting against double only fields":
16+
17+
- do:
18+
bulk:
19+
refresh: true
20+
body:
21+
- '{ "index" : { "_index" : "double_sort", "_id" : "1" } }'
22+
- '{"field" : [ 900719925474099.1, 1.1 ] }'
23+
- '{ "index" : { "_index" : "double_sort", "_id" : "2" } }'
24+
- '{"field" : [ 900719925474099.2, 900719925474099.3 ] }'
25+
- '{ "index" : { "_index" : "double_sort", "_id" : "3" } }'
26+
- '{"field" : [ 450359962737049.4, 3.5, 4.6 ] }'
27+
- '{ "index" : { "_index" : "double_sort", "_id" : "4" } }'
28+
- '{"field" : [ 450359962737049.7, 5.8, -1.9, -2.0 ] }'
29+
30+
- do:
31+
search:
32+
index: double_sort
33+
body:
34+
size: 5
35+
sort: [{ field: { mode: max, order: desc } } ]
36+
- match: {hits.total.value: 4 }
37+
- length: {hits.hits: 4 }
38+
- match: { hits.hits.0._index: double_sort }
39+
- match: { hits.hits.0._source.field: [ 900719925474099.2, 900719925474099.2 ] }
40+
- match: { hits.hits.0.sort.0: 900719925474099.2 }
41+
- match: { hits.hits.1._source.field: [ 900719925474099.1, 1.1 ] }
42+
- match: { hits.hits.1.sort.0: 900719925474099.1 }
43+
- match: { hits.hits.2._source.field: [ 450359962737049.7, 5.8, -1.9, -2.0 ] }
44+
- match: { hits.hits.2.sort.0: 450359962737049.7 }
45+
- match: { hits.hits.3._source.field: [ 450359962737049.4, 3.5, 4.6 ] }
46+
- match: { hits.hits.3.sort.0: 450359962737049.4 }
47+
48+
- do:
49+
search:
50+
index: double_sort
51+
body:
52+
size: 5
53+
sort: [ { field: { mode: max, order: asc } } ]
54+
- match: { hits.total.value: 4 }
55+
- length: { hits.hits: 4 }
56+
- match: { hits.hits.0._index: double_sort }
57+
- match: { hits.hits.0._source.field: [ 450359962737049.4, 3.5, 4.6 ] }
58+
- match: { hits.hits.0.sort.0: 450359962737049.4 }
59+
- match: { hits.hits.1._source.field: [ 450359962737049.7, 5.8, -1.9, -2.0 ] }
60+
- match: { hits.hits.1.sort.0: 450359962737049.7 }
61+
- match: { hits.hits.2._source.field: [ 900719925474099.1, 1.1 ] }
62+
- match: { hits.hits.2.sort.0: 900719925474099.1 }
63+
- match: { hits.hits.3._source.field: [ 900719925474099.2, 900719925474099.2 ] }
64+
- match: { hits.hits.3.sort.0: 900719925474099.2 }
65+
66+
- do:
67+
search:
68+
index: double_sort
69+
body:
70+
size: 5
71+
sort: [ { field: { mode: min, order: asc } } ]
72+
- match: { hits.total.value: 4 }
73+
- length: { hits.hits: 4 }
74+
- match: { hits.hits.0._index: double_sort }
75+
- match: { hits.hits.0._source.field: [ 450359962737049.7, 5.8, -1.9, -2.0 ] }
76+
- match: { hits.hits.0.sort: [ -2.0 ] }
77+
- match: { hits.hits.1._source.field: [ 900719925474099.1, 1.1 ] }
78+
- match: { hits.hits.1.sort.0: 1.1 }
79+
- match: { hits.hits.2._source.field: [ 450359962737049.4, 3.5, 4.6 ] }
80+
- match: { hits.hits.2.sort.0: 3.5 }
81+
- match: { hits.hits.3._source.field: [ 900719925474099.2, 900719925474099.2 ] }
82+
- match: { hits.hits.3.sort.0: 900719925474099.2 }
83+
84+
- do:
85+
search:
86+
index: double_sort
87+
body:
88+
size: 5
89+
sort: [ { field: { mode: median, order: desc } } ]
90+
- match: { hits.total.value: 4 }
91+
- length: { hits.hits: 4 }
92+
- match: { hits.hits.0._index: double_sort }
93+
- match: { hits.hits.0._source.field: [ 900719925474099.2, 900719925474099.2 ] }
94+
- match: { hits.hits.0.sort.0: 900719925474099.2 }
95+
- match: { hits.hits.1._source.field: [ 900719925474099.1, 1.1 ] }
96+
- match: { hits.hits.1.sort.0: 450359962737050.1 }
97+
- match: { hits.hits.2._source.field: [ 450359962737049.4, 3.5, 4.6 ] }
98+
- match: { hits.hits.2.sort.0: 4.6 }
99+
- match: { hits.hits.3._source.field: [ 450359962737049.7, 5.8, -1.9, -2.0 ] }
100+
- match: { hits.hits.3.sort.0: 1.95 }
101+
102+
- do:
103+
search:
104+
index: double_sort
105+
body:
106+
size: 5
107+
sort: [ { field: { mode: avg, order: asc } } ]
108+
- match: { hits.total.value: 4 }
109+
- length: { hits.hits: 4 }
110+
- match: { hits.hits.0._index: double_sort }
111+
- match: { hits.hits.0._source.field: [ 450359962737049.7, 5.8, -1.9, -2.0 ] }
112+
- match: { hits.hits.0.sort.0: 112589990684262.89 }
113+
- match: { hits.hits.1._source.field: [ 450359962737049.4, 3.5, 4.6 ] }
114+
- match: { hits.hits.1.sort.0: 150119987579019.16 }
115+
- match: { hits.hits.2._source.field: [ 900719925474099.1, 1.1 ] }
116+
- match: { hits.hits.2.sort.0: 450359962737050.1 }
117+
- match: { hits.hits.3._source.field: [ 900719925474099.2, 900719925474099.2 ] }
118+
- match: { hits.hits.3.sort.0: 900719925474099.2 }
119+
120+
- do:
121+
search:
122+
index: double_sort
123+
body:
124+
size: 5
125+
sort: [ { field: { mode: sum, order: desc } } ]
126+
- match: { hits.total.value: 4 }
127+
- length: { hits.hits: 4 }
128+
- match: { hits.hits.0._index: double_sort }
129+
- match: { hits.hits.0._source.field: [ 900719925474099.2, 900719925474099.2 ] }
130+
- match: { hits.hits.0.sort.0: 1801439850948198.5 }
131+
- match: { hits.hits.1._source.field: [ 900719925474099.1, 1.1 ] }
132+
- match: { hits.hits.1.sort.0: 900719925474100.2 }
133+
- match: { hits.hits.2._source.field: [ 450359962737049.4, 3.5, 4.6 ] }
134+
- match: { hits.hits.2.sort.0: 450359962737057.5 }
135+
- match: { hits.hits.3._source.field: [ 450359962737049.7, 5.8, -1.9, -2.0 ] }
136+
- match: { hits.hits.3.sort.0: 450359962737051.56 }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
setup:
2+
- do:
3+
indices.create:
4+
index: long_sort
5+
body:
6+
settings:
7+
number_of_shards: 3
8+
number_of_replicas: 0
9+
mappings:
10+
properties:
11+
field:
12+
type: long
13+
14+
---
15+
"test sorting against long only fields":
16+
17+
- do:
18+
bulk:
19+
refresh: true
20+
body:
21+
- '{ "index" : { "_index" : "long_sort", "_id" : "1" } }'
22+
- '{"field" : [ 9223372036854775807, 1 ] }'
23+
- '{ "index" : { "_index" : "long_sort", "_id" : "2" } }'
24+
- '{"field" : [ 922337203685477777, 2 ] }'
25+
- '{ "index" : { "_index" : "long_sort", "_id" : "3" } }'
26+
- '{"field" : [ 2147483647, 3, 4 ] }'
27+
- '{ "index" : { "_index" : "long_sort", "_id" : "4" } }'
28+
- '{"field" : [ 2147483648, 5, -1, -2 ] }'
29+
30+
- do:
31+
search:
32+
index: long_sort
33+
body:
34+
size: 5
35+
sort: [{ field: { mode: max, order: desc } } ]
36+
- match: {hits.total.value: 4 }
37+
- length: {hits.hits: 4 }
38+
- match: { hits.hits.0._index: long_sort }
39+
- match: { hits.hits.0._source.field: [ 9223372036854775807, 1 ] }
40+
- match: { hits.hits.0.sort.0: 9223372036854775807 }
41+
- match: { hits.hits.1._source.field: [ 922337203685477777, 2 ] }
42+
- match: { hits.hits.1.sort.0: 922337203685477777 }
43+
- match: { hits.hits.2._source.field: [ 2147483648, 5, -1, -2 ] }
44+
- match: { hits.hits.2.sort.0: 2147483648 }
45+
- match: { hits.hits.3._source.field: [ 2147483647, 3, 4 ] }
46+
- match: { hits.hits.3.sort.0: 2147483647 }
47+
48+
- do:
49+
search:
50+
index: long_sort
51+
body:
52+
size: 5
53+
sort: [ { field: { mode: max, order: asc } } ]
54+
- match: { hits.total.value: 4 }
55+
- length: { hits.hits: 4 }
56+
- match: { hits.hits.0._index: long_sort }
57+
- match: { hits.hits.0._source.field: [ 2147483647, 3, 4 ] }
58+
- match: { hits.hits.0.sort.0: 2147483647 }
59+
- match: { hits.hits.1._source.field: [ 2147483648, 5, -1, -2 ] }
60+
- match: { hits.hits.1.sort.0: 2147483648 }
61+
- match: { hits.hits.2._source.field: [ 922337203685477777, 2 ] }
62+
- match: { hits.hits.2.sort.0: 922337203685477777 }
63+
- match: { hits.hits.3._source.field: [ 9223372036854775807, 1 ] }
64+
- match: { hits.hits.3.sort.0: 9223372036854775807 }
65+
66+
67+
- do:
68+
search:
69+
index: long_sort
70+
body:
71+
size: 5
72+
sort: [{ field: { mode: min, order: desc } } ]
73+
- match: { hits.total.value: 4 }
74+
- length: { hits.hits: 4 }
75+
- match: { hits.hits.0._index: long_sort }
76+
- match: { hits.hits.0._source.field: [ 2147483647, 3, 4 ] }
77+
- match: { hits.hits.0.sort.0: 3 }
78+
- match: { hits.hits.1._source.field: [ 922337203685477777, 2 ] }
79+
- match: { hits.hits.1.sort.0: 2 }
80+
- match: { hits.hits.2._source.field: [ 9223372036854775807, 1 ] }
81+
- match: { hits.hits.2.sort.0: 1 }
82+
- match: { hits.hits.3._source.field: [ 2147483648, 5, -1, -2 ] }
83+
- match: { hits.hits.3.sort: [ -2 ] }
84+
85+
- do:
86+
search:
87+
index: long_sort
88+
body:
89+
size: 5
90+
sort: [ { field: { mode: median, order: asc } } ]
91+
- match: { hits.total.value: 4 }
92+
- length: { hits.hits: 4 }
93+
- match: { hits.hits.0._index: long_sort }
94+
- match: { hits.hits.0._source.field: [ 2147483648, 5, -1, -2 ] }
95+
- match: { hits.hits.0.sort.0: 2 }
96+
- match: { hits.hits.1._source.field: [ 2147483647, 3, 4 ] }
97+
- match: { hits.hits.1.sort.0: 4 }
98+
- match: { hits.hits.2._source.field: [ 922337203685477777, 2 ] }
99+
- match: { hits.hits.2.sort.0: 461168601842738880 }
100+
- match: { hits.hits.3._source.field: [ 9223372036854775807, 1 ] }
101+
- match: { hits.hits.3.sort.0: 4611686018427387904 }
102+
103+
- do:
104+
search:
105+
index: long_sort
106+
body:
107+
size: 5
108+
sort: [ { field: { mode: avg, order: desc } } ]
109+
- match: { hits.total.value: 4 }
110+
- length: { hits.hits: 4 }
111+
- match: { hits.hits.0._index: long_sort }
112+
- match: { hits.hits.0._source.field: [ 922337203685477777, 2 ] }
113+
- match: { hits.hits.0.sort.0: 461168601842738880 }
114+
- match: { hits.hits.1._source.field: [ 2147483647, 3, 4 ] }
115+
- match: { hits.hits.1.sort.0: 715827885 }
116+
- match: { hits.hits.2._source.field: [ 2147483648, 5, -1, -2 ] }
117+
- match: { hits.hits.2.sort.0: 536870913 }
118+
- match: { hits.hits.3._source.field: [ 9223372036854775807, 1 ] }
119+
- match: { hits.hits.3.sort: [ -4611686018427387904 ] }
120+
121+
- do:
122+
search:
123+
index: long_sort
124+
body:
125+
size: 5
126+
sort: [ { field: { mode: sum, order: asc } } ]
127+
- match: { hits.total.value: 4 }
128+
- length: { hits.hits: 4 }
129+
- match: { hits.hits.0._index: long_sort }
130+
- match: { hits.hits.0._source.field: [ 9223372036854775807, 1 ] }
131+
- match: { hits.hits.0.sort: [ -9223372036854775808 ] }
132+
- match: { hits.hits.1._source.field: [ 2147483648, 5, -1, -2 ] }
133+
- match: { hits.hits.1.sort.0: 2147483650 }
134+
- match: { hits.hits.2._source.field: [ 2147483647, 3, 4 ] }
135+
- match: { hits.hits.2.sort.0: 2147483654 }
136+
- match: { hits.hits.3._source.field: [ 922337203685477777, 2 ] }
137+
- match: { hits.hits.3.sort.0: 922337203685477779 }

0 commit comments

Comments
 (0)