Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP [Discover] Migrate field existence to API request #138125

Closed
kertal opened this issue Aug 4, 2022 · 2 comments
Closed

WIP [Discover] Migrate field existence to API request #138125

kertal opened this issue Aug 4, 2022 · 2 comments
Labels
Feature:Discover Discover Application Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL.

Comments

@kertal
Copy link
Member

kertal commented Aug 4, 2022

Currently in Discover, we calculate the available fields by the data returned by Elasticsearch.

Bildschirmfoto 2022-08-08 um 10 45 39

To show all fields users need to change the Hide empty fields filter

Bildschirmfoto 2022-08-08 um 10 49 52

Here's where the field statistics are calculated:

useEffect(() => {
const subscription = props.documents$.subscribe((next) => {
if (next.fetchStatus !== documentState.fetchStatus) {
if (next.result) {
fieldCounts.current = calcFieldCounts(next.result, selectedDataView!);
}
setDocumentState({ ...documentState, ...next });
}
});
return () => subscription.unsubscribe();
}, [props.documents$, selectedDataView, documentState, setDocumentState]);

Here's where available fields + selected fields are sent to the field statistics by observable (Note: sending selected fields should not be necessary, since it's in our state, to send the available fields by observable is something we could reconsider, POC PR: #138238)

useEffect(
() => {
// For an external embeddable like the Field stats
// it is useful to know what fields are populated in the docs fetched
// or what fields are selected by the user
const fieldCnts = fieldCounts.current ?? {};
const availableFields = props.columns.length > 0 ? props.columns : Object.keys(fieldCnts);
availableFields$.next({
fetchStatus: FetchStatus.COMPLETE,
fields: availableFields,
});
},

Here's where the grouping of the fields into (selected, popular, unpopular 😢 ) takes place:

const {
selected: selectedFields,
popular: popularFields,
unpopular: unpopularFields,
} = useMemo(
() => groupFields(fields, columns, popularLimit, fieldCounts, fieldFilter, useNewFieldsApi),
[fields, columns, popularLimit, fieldCounts, fieldFilter, useNewFieldsApi]
);

This should be rewritten using in the way Lens works, which requests those fields from Elasticsearch, with the addition, that it should also work with virtual fields for our text based query initiative. With the merge of #137031 the function for getting this available fields will be migrated from server -> public.

Here's how it currently works in Lens:

syncExistingFields({
dateRange,
setState,
isFirstExistenceFetch: state.isFirstExistenceFetch,
currentIndexPatternTitle: indexPatterns[currentIndexPatternId]?.title || '',
showNoDataPopover,
indexPatterns: indexPatternList,
fetchJson: core.http.post,
dslQuery,

@kertal kertal added Feature:Discover Discover Application Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. labels Aug 4, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@kertal
Copy link
Member Author

kertal commented Aug 8, 2022

Closing in favor of #135678

@kertal kertal closed this as completed Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Discover Discover Application Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL.
Projects
None yet
Development

No branches or pull requests

2 participants