[Reporting] Fix discover to include the unmapped fields in the sharing data (#132972)

This commit is contained in:
Michael Dokolin 2022-06-01 22:32:56 +02:00 committed by GitHub
parent b3892cf21c
commit d06c193915
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 146 additions and 8 deletions

View file

@ -146,13 +146,13 @@ describe('getSharingData', () => {
services
);
expect(getSearchSource().fields).toStrictEqual([
'cool-timefield',
'cool-field-1',
'cool-field-2',
'cool-field-3',
'cool-field-4',
'cool-field-5',
'cool-field-6',
{ field: 'cool-timefield', include_unmapped: 'true' },
{ field: 'cool-field-1', include_unmapped: 'true' },
{ field: 'cool-field-2', include_unmapped: 'true' },
{ field: 'cool-field-3', include_unmapped: 'true' },
{ field: 'cool-field-4', include_unmapped: 'true' },
{ field: 'cool-field-5', include_unmapped: 'true' },
{ field: 'cool-field-6', include_unmapped: 'true' },
]);
});

View file

@ -96,7 +96,10 @@ export async function getSharingData(
*/
const useFieldsApi = !config.get(SEARCH_FIELDS_FROM_SOURCE);
if (useFieldsApi && columns.length) {
searchSource.setField('fields', columns);
searchSource.setField(
'fields',
columns.map((field) => ({ field, include_unmapped: 'true' }))
);
}
return searchSource.getSerializedFields(true);
},

View file

@ -0,0 +1,25 @@
{
"type": "doc",
"value": {
"id": "1",
"index": "recipes",
"source": {
"text":"text1",
"unmapped": "unmapped1"
}
}
}
{
"type": "doc",
"value": {
"id": "2",
"index": "recipes",
"source": {
"text":"text2",
"nested": {
"unmapped": "unmapped2"
}
}
}
}

View file

@ -0,0 +1,14 @@
{
"type": "index",
"value": {
"index": "recipes",
"mappings": {
"dynamic": false,
"properties": {
"text": {
"type": "text"
}
}
}
}
}

View file

@ -0,0 +1,15 @@
{
"attributes": {
"fields": "[]",
"title": "recipes"
},
"coreMigrationVersion": "8.3.0",
"id": "5c620ea0-dc4f-11ec-972a-bf98ce1eebd7",
"migrationVersion": {
"index-pattern": "8.0.0"
},
"references": [],
"type": "index-pattern",
"updated_at": "2022-05-25T17:23:15.216Z",
"version": "WzE4NywxXQ=="
}

View file

@ -8,3 +8,24 @@ bwMtOW0BH63Xcmy432HJ,ecommerce,\\"-\\",\\"Men's Clothing, Men's Shoes\\",\\"Men'
5AMtOW0BH63Xcmy432HJ,ecommerce,\\"-\\",\\"Men's Clothing\\",\\"Men's Clothing\\",EUR,Kamal,Kamal,\\"Kamal Salazar\\",\\"Kamal Salazar\\",MALE,39,Salazar,Salazar,\\"(empty)\\",Tuesday,1,\\"kamal@salazar-family.zzz\\",Istanbul,Asia,TR,\\"POINT (29 41)\\",Istanbul,\\"Spherecords, Spritechnologies\\",\\"Spherecords, Spritechnologies\\",\\"Jun 24, 2019 @ 00:00:00.000\\",567736,\\"sold_product_567736_24718, sold_product_567736_24306\\",\\"sold_product_567736_24718, sold_product_567736_24306\\",\\"11.992, 75\\",\\"11.992, 75\\",\\"Men's Clothing, Men's Clothing\\",\\"Men's Clothing, Men's Clothing\\",\\"Dec 13, 2016 @ 00:00:00.000, Dec 13, 2016 @ 00:00:00.000\\",\\"0, 0\\",\\"0, 0\\",\\"Spherecords, Spritechnologies\\",\\"Spherecords, Spritechnologies\\",\\"6.109, 36.75\\",\\"11.992, 75\\",\\"24,718, 24,306\\",\\"Pyjama bottoms - light grey multicolor, Waterproof trousers - scarlet\\",\\"Pyjama bottoms - light grey multicolor, Waterproof trousers - scarlet\\",\\"1, 1\\",\\"ZO0663706637, ZO0620906209\\",\\"0, 0\\",\\"11.992, 75\\",\\"11.992, 75\\",\\"0, 0\\",\\"ZO0663706637, ZO0620906209\\",87,87,2,2,order,kamal
"
`;
exports[`Reporting APIs Generate CSV from SearchSource with unmapped fields includes all unmapped fields to the report 1`] = `
"\\"_id\\",\\"_index\\",\\"_score\\",\\"nested.unmapped\\",text,unmapped
1,recipes,\\"-\\",\\"-\\",text1,unmapped1
2,recipes,\\"-\\",unmapped2,text2,\\"-\\"
"
`;
exports[`Reporting APIs Generate CSV from SearchSource with unmapped fields includes an unmapped field to the report 1`] = `
"\\"_id\\",\\"_index\\",\\"_score\\",text,unmapped
1,recipes,\\"-\\",text1,unmapped1
2,recipes,\\"-\\",text2,\\"-\\"
"
`;
exports[`Reporting APIs Generate CSV from SearchSource with unmapped fields includes an unmapped nested field to the report 1`] = `
"\\"_id\\",\\"_index\\",\\"_score\\",\\"nested.unmapped\\",text
1,recipes,\\"-\\",\\"-\\",text1
2,recipes,\\"-\\",unmapped2,text2
"
`;

View file

@ -12,6 +12,8 @@ import { FtrProviderContext } from '../ftr_provider_context';
// eslint-disable-next-line import/no-default-export
export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
const reportingAPI = getService('reportingAPI');
describe('Generate CSV from SearchSource', () => {
@ -71,5 +73,63 @@ export default function ({ getService }: FtrProviderContext) {
await reportingAPI.teardownEcommerce();
await reportingAPI.deleteAllReports();
});
describe('with unmapped fields', () => {
before(async () => {
await esArchiver.loadIfNeeded(
'x-pack/test/functional/es_archives/reporting/unmapped_fields'
);
await kibanaServer.importExport.load(
'x-pack/test/functional/fixtures/kbn_archiver/reporting/unmapped_fields.json'
);
});
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/reporting/unmapped_fields');
await kibanaServer.importExport.unload(
'x-pack/test/functional/fixtures/kbn_archiver/reporting/unmapped_fields.json'
);
});
async function generateCsvReport(fields: string[]) {
const { text } = await reportingAPI.generateCsv({
title: 'CSV Report',
browserTimezone: 'UTC',
objectType: 'search',
version: '7.15.0',
searchSource: {
version: true,
query: { query: '', language: 'kuery' },
index: '5c620ea0-dc4f-11ec-972a-bf98ce1eebd7',
sort: [{ order_date: 'desc' }],
fields: fields.map((field) => ({ field, include_unmapped: 'true' })),
filter: [],
} as SerializedSearchSourceFields,
});
const { path } = JSON.parse(text) as { path: string };
await reportingAPI.waitForJobToFinish(path);
return reportingAPI.getCompletedJobOutput(path);
}
it('includes an unmapped field to the report', async () => {
const csvFile = await generateCsvReport(['text', 'unmapped']);
expectSnapshot(csvFile).toMatch();
});
it('includes an unmapped nested field to the report', async () => {
const csvFile = await generateCsvReport(['text', 'nested.unmapped']);
expectSnapshot(csvFile).toMatch();
});
it('includes all unmapped fields to the report', async () => {
const csvFile = await generateCsvReport(['*']);
expectSnapshot(csvFile).toMatch();
});
});
});
}