fixes csv export of saved searches that have _source field (#43123)

* fixes csv export of saved searches that have _source field

* adding test
This commit is contained in:
Bill McConaghy 2019-08-12 16:14:08 -04:00 committed by GitHub
parent d205f1e456
commit 142897fbc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -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);

View file

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