Skip to content

Commit

Permalink
Guard against invalid sorting fields in report generation (#458) (#471)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7f69dc4)

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
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>
  • Loading branch information
1 parent 3db1c45 commit 583e6ce
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions server/routes/utils/dataReportHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,21 @@ export const buildRequestBody = (
.query(esbBoolQuery)
.version(true);

if (report._source.sorting.length > 0) {
const sortings: Sort[] = report._source.sorting.map((element: string[]) => {
let sorting: string[][] = report._source.sorting;

// We expect a list of [field, order] pairs for sorting. In some migration paths, though it's not
// clear why, this list can get unnested in the case of one sort, [["field", "asc"]] becomes
// ["field", "asc"]. The true root cause remains a mystery, so we work around it.
// See: https://github.com/opensearch-project/dashboards-reporting/issues/371
if (sorting.length > 0 && typeof sorting[0] === "string") {
sorting = [(sorting as unknown as string[])];
}

if (sorting.length > 0) {
const sorts: Sort[] = sorting.map((element: string[]) => {
return esb.sort(element[0], element[1]);
});
esbSearchQuery.sorts(sortings);
esbSearchQuery.sorts(sorts);
}

// add selected fields to query
Expand Down

0 comments on commit 583e6ce

Please sign in to comment.