elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.51k stars 8.07k forks source link

[Discover] Move total count logic from UnifiedHistogram to Discover main #177156

Open jughosta opened 5 months ago

jughosta commented 5 months ago

Currently, Discover passes filters, query and time range to UnifiedHistogram component and UnifiedHistogram component reports back the total count of documents matching the query.

If chart is visible, UnifiedHistogram fetches chart data and derives total count from that request. In some ES|QL cases, Discover passes table with already fetched results and UnifiedHistogram derives total count from that passed data. Then it reports the result back to Discover.

If chart is hidden, UnifiedHistogram makes a request to fetch only total count for both data view and ES|QL modes. Then it reports the result back to Discover.

Also there are issues with having redundant requests from UnifiedHistogram https://github.com/elastic/kibana/issues/165192

The logic is getting complicated and seems like that this back and forth between UnifiedHistogram and Discover can become a problem of reporting an incorrect total hits count in the future. During the development I ran into an issue once (time range was not updated in UnifiedHistogram correctly) when 0 was coming from UnifiedHistogram and it was triggering "No results" screen in Discover although Discover request had results.

So it's important to make sure that the same filters, query and time range are used both for Discover request and for total hits count request. We can achieve this by moving the logic of deriving total hits count out of the UnifiedHistogram and closer to the the Discover main request (as a separate _count request or with track_total_hits). And we should not use component props for passing filters, query and time range and relying on React hooks.

elasticmachine commented 5 months ago

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

jughosta commented 5 months ago

Another case: