From ee7b2151c9a9cff45a5cd270235a4d8a95f81931 Mon Sep 17 00:00:00 2001 From: Bill McConaghy Date: Mon, 12 Aug 2019 13:35:00 -0400 Subject: [PATCH 1/2] fixes csv export of saved searches that have _source field --- .../export_types/csv/server/lib/format_csv_values.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/format_csv_values.js b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/format_csv_values.js index b54659da617d0..9083e8ce04f88 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/format_csv_values.js +++ b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/format_csv_values.js @@ -10,7 +10,12 @@ export function createFormatCsvValues(escapeValue, separator, fields, formatsMap return function formatCsvValues(values) { return fields .map(field => { - const value = values[field]; + let value; + if (field === '_source') { + value = values; + } else { + value = values[field]; + } if (isNull(value) || isUndefined(value)) { return ''; } From b6140414c851103bcf638bcd1dec8dbdcb486125 Mon Sep 17 00:00:00 2001 From: Bill McConaghy Date: Mon, 12 Aug 2019 14:24:01 -0400 Subject: [PATCH 2/2] adding test --- .../csv/server/lib/__tests__/format_csv_values.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/__tests__/format_csv_values.js b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/__tests__/format_csv_values.js index e3d588b5f48f1..748ab54b8592e 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/__tests__/format_csv_values.js +++ b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/__tests__/format_csv_values.js @@ -11,7 +11,16 @@ describe('formatCsvValues', function () { const separator = ','; const fields = ['foo', 'bar']; const mockEscapeValue = val => val; - + describe('with _source as one of the fields', function () { + const formatsMap = new Map(); + const formatCsvValues = createFormatCsvValues(mockEscapeValue, separator, ['foo', '_source'], formatsMap); + it('should return full _source for _source field', function () { + const values = { + foo: 'baz', + }; + expect(formatCsvValues(values)).to.be('baz,{"foo":"baz"}'); + }); + }); describe('without field formats', function () { const formatsMap = new Map(); const formatCsvValues = createFormatCsvValues(mockEscapeValue, separator, fields, formatsMap);