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); 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 ''; }