From 757076631c7fcbc33169de017466f261df7efd67 Mon Sep 17 00:00:00 2001 From: Tre' Seymour Date: Wed, 3 Apr 2024 10:59:06 +0100 Subject: [PATCH 1/3] [serverless] add sorting --- .../__snapshots__/generate_csv_discover.snap | 8 ++++---- .../common/reporting/generate_csv_discover.ts | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/x-pack/test_serverless/api_integration/test_suites/common/reporting/__snapshots__/generate_csv_discover.snap b/x-pack/test_serverless/api_integration/test_suites/common/reporting/__snapshots__/generate_csv_discover.snap index 6fec87412595fa..278e094610a847 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/reporting/__snapshots__/generate_csv_discover.snap +++ b/x-pack/test_serverless/api_integration/test_suites/common/reporting/__snapshots__/generate_csv_discover.snap @@ -85,10 +85,10 @@ exports[`Reporting Generate CSV from SearchSource with unmapped fields includes `; exports[`Reporting Generate CSV from SearchSource with unmapped fields includes an unmapped field to the report 1`] = ` -"\\"_id\\",\\"_index\\",\\"_score\\",text,unmapped -1,recipes,1,text1,unmapped1 -2,recipes,1,text2,\\"-\\" -" +"\\"_id\\",\\"_index\\",\\"_score\\",\\"-\\" +,1,1,recipes,recipes,text,text1,text2,unmapped +1,unmapped1 +2" `; exports[`Reporting Generate CSV from SearchSource with unmapped fields includes an unmapped nested field to the report 1`] = ` diff --git a/x-pack/test_serverless/api_integration/test_suites/common/reporting/generate_csv_discover.ts b/x-pack/test_serverless/api_integration/test_suites/common/reporting/generate_csv_discover.ts index db022dd4e81585..66db025d3d17c9 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/reporting/generate_csv_discover.ts +++ b/x-pack/test_serverless/api_integration/test_suites/common/reporting/generate_csv_discover.ts @@ -194,8 +194,16 @@ export default ({ getService }: FtrProviderContext) => { } it('includes an unmapped field to the report', async () => { - const csvFile = await generateCsvReportWithUnmapped(['text', 'unmapped']); - expect((csvFile as string).length).to.be(88); + const unsorted: string = (await generateCsvReportWithUnmapped([ + 'text', + 'unmapped', + ])) as string; + const csvFile: string = unsorted + .split(',') + .sort((a, b) => a.localeCompare(b)) + .join(','); + + expect(csvFile.length).to.be(88); expectSnapshot(createPartialCsv(csvFile)).toMatch(); }); From e491c2329e6200e70c07e1e7110e97158a8dff18 Mon Sep 17 00:00:00 2001 From: Tre' Seymour Date: Wed, 3 Apr 2024 13:05:12 +0100 Subject: [PATCH 2/3] Revert --- .../__snapshots__/generate_csv_discover.snap | 8 ++++---- .../common/reporting/generate_csv_discover.ts | 12 ++---------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/x-pack/test_serverless/api_integration/test_suites/common/reporting/__snapshots__/generate_csv_discover.snap b/x-pack/test_serverless/api_integration/test_suites/common/reporting/__snapshots__/generate_csv_discover.snap index 278e094610a847..6fec87412595fa 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/reporting/__snapshots__/generate_csv_discover.snap +++ b/x-pack/test_serverless/api_integration/test_suites/common/reporting/__snapshots__/generate_csv_discover.snap @@ -85,10 +85,10 @@ exports[`Reporting Generate CSV from SearchSource with unmapped fields includes `; exports[`Reporting Generate CSV from SearchSource with unmapped fields includes an unmapped field to the report 1`] = ` -"\\"_id\\",\\"_index\\",\\"_score\\",\\"-\\" -,1,1,recipes,recipes,text,text1,text2,unmapped -1,unmapped1 -2" +"\\"_id\\",\\"_index\\",\\"_score\\",text,unmapped +1,recipes,1,text1,unmapped1 +2,recipes,1,text2,\\"-\\" +" `; exports[`Reporting Generate CSV from SearchSource with unmapped fields includes an unmapped nested field to the report 1`] = ` diff --git a/x-pack/test_serverless/api_integration/test_suites/common/reporting/generate_csv_discover.ts b/x-pack/test_serverless/api_integration/test_suites/common/reporting/generate_csv_discover.ts index 66db025d3d17c9..db022dd4e81585 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/reporting/generate_csv_discover.ts +++ b/x-pack/test_serverless/api_integration/test_suites/common/reporting/generate_csv_discover.ts @@ -194,16 +194,8 @@ export default ({ getService }: FtrProviderContext) => { } it('includes an unmapped field to the report', async () => { - const unsorted: string = (await generateCsvReportWithUnmapped([ - 'text', - 'unmapped', - ])) as string; - const csvFile: string = unsorted - .split(',') - .sort((a, b) => a.localeCompare(b)) - .join(','); - - expect(csvFile.length).to.be(88); + const csvFile = await generateCsvReportWithUnmapped(['text', 'unmapped']); + expect((csvFile as string).length).to.be(88); expectSnapshot(createPartialCsv(csvFile)).toMatch(); }); From 7037a9e0b3c33a0a3a7a6793f969f772a72cea04 Mon Sep 17 00:00:00 2001 From: Tre' Seymour Date: Wed, 3 Apr 2024 15:31:23 +0100 Subject: [PATCH 3/3] Add sorting via api calls instead. Update mappings file to load field data. Update snapshots --- .../reporting/unmapped_fields/mappings.json | 3 ++- .../__snapshots__/generate_csv_discover.snap | 12 ++++++------ .../common/reporting/generate_csv_discover.ts | 7 ++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/x-pack/test/functional/es_archives/reporting/unmapped_fields/mappings.json b/x-pack/test/functional/es_archives/reporting/unmapped_fields/mappings.json index f7cf22b6e4198b..2ce48debb521c0 100644 --- a/x-pack/test/functional/es_archives/reporting/unmapped_fields/mappings.json +++ b/x-pack/test/functional/es_archives/reporting/unmapped_fields/mappings.json @@ -6,7 +6,8 @@ "dynamic": false, "properties": { "text": { - "type": "text" + "type": "text", + "fielddata": "true" } } } diff --git a/x-pack/test_serverless/api_integration/test_suites/common/reporting/__snapshots__/generate_csv_discover.snap b/x-pack/test_serverless/api_integration/test_suites/common/reporting/__snapshots__/generate_csv_discover.snap index 6fec87412595fa..21bc9ecdd106e5 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/reporting/__snapshots__/generate_csv_discover.snap +++ b/x-pack/test_serverless/api_integration/test_suites/common/reporting/__snapshots__/generate_csv_discover.snap @@ -79,21 +79,21 @@ xgMtOW0BH63Xcmy45GnD,ecommerce,\\"-\\",\\"Women's Clothing, Women's Shoes, Women exports[`Reporting Generate CSV from SearchSource with unmapped fields includes all unmapped fields to the report 1`] = ` "\\"_id\\",\\"_index\\",\\"_score\\",\\"nested.unmapped\\",text,unmapped -1,recipes,1,\\"-\\",text1,unmapped1 -2,recipes,1,unmapped2,text2,\\"-\\" +1,recipes,\\"-\\",\\"-\\",text1,unmapped1 +2,recipes,\\"-\\",unmapped2,text2,\\"-\\" " `; exports[`Reporting Generate CSV from SearchSource with unmapped fields includes an unmapped field to the report 1`] = ` "\\"_id\\",\\"_index\\",\\"_score\\",text,unmapped -1,recipes,1,text1,unmapped1 -2,recipes,1,text2,\\"-\\" +1,recipes,\\"-\\",text1,unmapped1 +2,recipes,\\"-\\",text2,\\"-\\" " `; exports[`Reporting Generate CSV from SearchSource with unmapped fields includes an unmapped nested field to the report 1`] = ` "\\"_id\\",\\"_index\\",\\"_score\\",\\"nested.unmapped\\",text -1,recipes,1,\\"-\\",text1 -2,recipes,1,unmapped2,text2 +1,recipes,\\"-\\",\\"-\\",text1 +2,recipes,\\"-\\",unmapped2,text2 " `; diff --git a/x-pack/test_serverless/api_integration/test_suites/common/reporting/generate_csv_discover.ts b/x-pack/test_serverless/api_integration/test_suites/common/reporting/generate_csv_discover.ts index db022dd4e81585..def29fb09096c2 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/reporting/generate_csv_discover.ts +++ b/x-pack/test_serverless/api_integration/test_suites/common/reporting/generate_csv_discover.ts @@ -184,6 +184,7 @@ export default ({ getService }: FtrProviderContext) => { query: { language: 'kuery', query: '' }, fields: fields.map((field) => ({ field, include_unmapped: 'true' })), filter: [], + sort: [{ text: 'asc' as SortDirection }], }, title: 'Untitled discover search', version: '8.14.0', @@ -195,19 +196,19 @@ export default ({ getService }: FtrProviderContext) => { it('includes an unmapped field to the report', async () => { const csvFile = await generateCsvReportWithUnmapped(['text', 'unmapped']); - expect((csvFile as string).length).to.be(88); + expect((csvFile as string).length).to.be(92); expectSnapshot(createPartialCsv(csvFile)).toMatch(); }); it('includes an unmapped nested field to the report', async () => { const csvFile = await generateCsvReportWithUnmapped(['text', 'nested.unmapped']); - expect((csvFile as string).length).to.be(97); + expect((csvFile as string).length).to.be(101); expectSnapshot(createPartialCsv(csvFile)).toMatch(); }); it('includes all unmapped fields to the report', async () => { const csvFile = await generateCsvReportWithUnmapped(['*']); - expect((csvFile as string).length).to.be(120); + expect((csvFile as string).length).to.be(124); expectSnapshot(createPartialCsv(csvFile)).toMatch(); }); });