Skip to content

Commit

Permalink
[ML] Fix Index data visualizer doc count when time field is not defin…
Browse files Browse the repository at this point in the history
…ed (elastic#142409)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit fdba8d3)
  • Loading branch information
qn895 committed Oct 3, 2022
1 parent 1780316 commit ac9c729
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const getDocumentCountStats = async (
},
});

const getSearchParams = (aggregations: unknown) => ({
const getSearchParams = (aggregations: unknown, trackTotalHits = false) => ({
index,
body: {
query,
Expand All @@ -133,13 +133,17 @@ export const getDocumentCountStats = async (
: {}),
...(isPopulatedObject(runtimeFieldMap) ? { runtime_mappings: runtimeFieldMap } : {}),
},
track_total_hits: false,
track_total_hits: trackTotalHits,
size: 0,
});
const firstResp = await search
.search(
{
params: getSearchParams(getAggsWithRandomSampling(initialDefaultProbability)),
params: getSearchParams(
getAggsWithRandomSampling(initialDefaultProbability),
// Track total hits if time field is not defined
timeFieldName === undefined
),
},
searchOptions
)
Expand All @@ -152,6 +156,22 @@ export const getDocumentCountStats = async (
)}`
);
}

// If time field is not defined, no need to show the document count chart
// Just need to return the tracked total hits
if (timeFieldName === undefined) {
const trackedTotalHits =
typeof firstResp.rawResponse.hits.total === 'number'
? firstResp.rawResponse.hits.total
: firstResp.rawResponse.hits.total?.value;
return {
...result,
randomlySampled: false,
took: firstResp.rawResponse.took,
totalCount: trackedTotalHits ?? 0,
};
}

if (isDefined(probability)) {
return {
...result,
Expand Down

0 comments on commit ac9c729

Please sign in to comment.