From 55936ac60a2f22d7a769901d8153b9af0c7fa79c Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Mon, 3 Apr 2023 17:27:04 -0400 Subject: [PATCH] Fixing SortField comparison to use equals instead of reference equality (#6901) Signed-off-by: Andriy Redko --- .../test/search/260_sort_mixed.yml | 71 +++++++++++++++++++ .../action/search/SearchPhaseController.java | 2 +- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/search/260_sort_mixed.yml diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/260_sort_mixed.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/260_sort_mixed.yml new file mode 100644 index 0000000000000..321883a1063e7 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/260_sort_mixed.yml @@ -0,0 +1,71 @@ +"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: + settings: + number_of_shards: "1" + number_of_replicas: "0" + mappings: + properties: + counter: + type: long + + - do: + indices.create: + index: test_2 + body: + settings: + number_of_shards: "1" + number_of_replicas: "0" + 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] } diff --git a/server/src/main/java/org/opensearch/action/search/SearchPhaseController.java b/server/src/main/java/org/opensearch/action/search/SearchPhaseController.java index a141d2a0680d6..6199af11a565f 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchPhaseController.java +++ b/server/src/main/java/org/opensearch/action/search/SearchPhaseController.java @@ -635,7 +635,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; } }