[8.15] [Discover] Fix Field Statistics when discover:searchFieldsFromSource is enabled (#187250) (#188078)

# Backport

This will backport the following commits from `main` to `8.15`:
- [[Discover] Fix Field Statistics when discover:searchFieldsFromSource
is enabled (#187250)](https://github.com/elastic/kibana/pull/187250)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Julia
Rechkunova","email":"julia.rechkunova@elastic.co"},"sourceCommit":{"committedDate":"2024-07-11T10:22:15Z","message":"[Discover]
Fix Field Statistics when discover:searchFieldsFromSource is enabled
(#187250)\n\n- Closes
https://github.com/elastic/kibana/issues/187241\r\n\r\n##
Summary\r\n\r\nThis PR excludes `_source` when processing current
`columns` in UI\r\n- For Field Statistics table\r\n- For ES|QL fields
callout\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Matthias Wilhelm
<matthias.wilhelm@elastic.co>","sha":"879b7b7d9880a99b693685697c435ad9f14159c9","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:DataDiscovery","backport:prev-minor","v8.16.0"],"title":"[Discover]
Fix Field Statistics when discover:searchFieldsFromSource is
enabled","number":187250,"url":"https://github.com/elastic/kibana/pull/187250","mergeCommit":{"message":"[Discover]
Fix Field Statistics when discover:searchFieldsFromSource is enabled
(#187250)\n\n- Closes
https://github.com/elastic/kibana/issues/187241\r\n\r\n##
Summary\r\n\r\nThis PR excludes `_source` when processing current
`columns` in UI\r\n- For Field Statistics table\r\n- For ES|QL fields
callout\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Matthias Wilhelm
<matthias.wilhelm@elastic.co>","sha":"879b7b7d9880a99b693685697c435ad9f14159c9"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/187250","number":187250,"mergeCommit":{"message":"[Discover]
Fix Field Statistics when discover:searchFieldsFromSource is enabled
(#187250)\n\n- Closes
https://github.com/elastic/kibana/issues/187241\r\n\r\n##
Summary\r\n\r\nThis PR excludes `_source` when processing current
`columns` in UI\r\n- For Field Statistics table\r\n- For ES|QL fields
callout\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Matthias Wilhelm
<matthias.wilhelm@elastic.co>","sha":"879b7b7d9880a99b693685697c435ad9f14159c9"}}]}]
BACKPORT-->

Co-authored-by: Julia Rechkunova <julia.rechkunova@elastic.co>
This commit is contained in:
Kibana Machine 2024-07-11 13:57:05 +02:00 committed by GitHub
parent e0c1e4bfb4
commit 279152a274
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 81 additions and 2 deletions

View file

@ -56,7 +56,12 @@ export const FieldStatisticsTable = React.memo((props: FieldStatisticsTableProps
} = props;
const visibleFields = useMemo(
() => convertFieldsToFallbackFields({ fields: columns, additionalFieldGroups }),
() =>
convertFieldsToFallbackFields({
// `discover:searchFieldsFromSource` adds `_source` to the columns, but we should exclude it for Field Statistics
fields: columns.filter((col) => col !== '_source'),
additionalFieldGroups,
}),
[additionalFieldGroups, columns]
);
const allFallbackFields = useMemo(

View file

@ -277,7 +277,8 @@ function DiscoverDocumentsComponent({
<>
<SelectedVSAvailableCallout
esqlQueryColumns={documents?.esqlQueryColumns}
selectedColumns={currentColumns}
// `discover:searchFieldsFromSource` adds `_source` to the columns, but we should exclude it from the callout
selectedColumns={currentColumns.filter((col) => col !== '_source')}
/>
<SearchResponseWarningsCallout warnings={documentState.interceptedWarnings ?? []} />
</>

View file

@ -0,0 +1,72 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { FtrProviderContext } from '../ftr_provider_context';
export default function ({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['common', 'discover', 'timePicker', 'header']);
const esArchiver = getService('esArchiver');
const testSubjects = getService('testSubjects');
const kibanaServer = getService('kibanaServer');
const security = getService('security');
const defaultSettings = {
defaultIndex: 'logstash-*',
};
describe('discover field statistics table', function () {
before(async () => {
await security.testUser.setRoles(['kibana_admin', 'test_logstash_reader']);
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover');
});
after(async () => {
await kibanaServer.importExport.unload('test/functional/fixtures/kbn_archiver/discover');
await esArchiver.unload('test/functional/fixtures/es_archiver/logstash_functional');
await kibanaServer.savedObjects.cleanStandardList();
});
[true, false].forEach((shouldSearchFieldsFromSource) => {
describe(`discover:searchFieldsFromSource: ${shouldSearchFieldsFromSource}`, function () {
before(async function () {
await PageObjects.timePicker.setDefaultAbsoluteRangeViaUiSettings();
await kibanaServer.uiSettings.update({
...defaultSettings,
'discover:searchFieldsFromSource': shouldSearchFieldsFromSource,
});
await PageObjects.common.navigateToApp('discover');
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.waitUntilSearchingHasFinished();
});
after(async () => {
await kibanaServer.uiSettings.replace({});
});
it('should show Field Statistics data in data view mode', async () => {
await testSubjects.click('dscViewModeFieldStatsButton');
await PageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.existOrFail('dataVisualizerTableContainer');
await testSubjects.click('dscViewModeDocumentButton');
await PageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.existOrFail('discoverDocTable');
});
it('should show Field Statistics data in ES|QL mode', async () => {
await PageObjects.discover.selectTextBaseLang();
await PageObjects.discover.waitUntilSearchingHasFinished();
await testSubjects.click('dscViewModeFieldStatsButton');
await PageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.existOrFail('dataVisualizerTableContainer');
});
});
});
});
}

View file

@ -25,5 +25,6 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./_time_field_column'));
loadTestFile(require.resolve('./_unsaved_changes_badge'));
loadTestFile(require.resolve('./_view_mode_toggle'));
loadTestFile(require.resolve('./_field_stats_table'));
});
}