Skip to content

Commit

Permalink
fixes csv export of saved searches that have _source field (elastic#4…
Browse files Browse the repository at this point in the history
…3123)

* fixes csv export of saved searches that have _source field

* adding test
  • Loading branch information
bmcconaghy committed Aug 12, 2019
1 parent a51ed7f commit 8fb330c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
Expand Down

0 comments on commit 8fb330c

Please sign in to comment.