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

[ML] Fix Index data visualizer doc count when time field is not defined #142409

Merged
merged 2 commits into from
Oct 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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