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

[Discover][ES|QL] Show field stats per records instead of per values #183176

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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 @@ -567,7 +567,7 @@ function getCountsElement(
): JSX.Element {
const dataTestSubjDocsCount = 'unifiedFieldStats-statsFooter-docsCount';
const { fieldFormats } = services;
const { totalDocuments, sampledValues, sampledDocuments, topValues } = state;
const { totalDocuments, sampledDocuments } = state;

if (!totalDocuments) {
return <></>;
Expand All @@ -576,7 +576,7 @@ function getCountsElement(
let labelElement;

if (isTextBased) {
labelElement = topValues?.areExamples ? (
labelElement = (
<FormattedMessage
id="unifiedFieldList.fieldStats.calculatedFromSampleRecordsLabel"
defaultMessage="Calculated from {sampledDocumentsFormatted} sample {sampledDocuments, plural, one {record} other {records}}."
Expand All @@ -591,21 +591,6 @@ function getCountsElement(
),
}}
/>
) : (
<FormattedMessage
id="unifiedFieldList.fieldStats.calculatedFromSampleValuesLabel"
defaultMessage="Calculated from {sampledValuesFormatted} sample {sampledValues, plural, one {value} other {values}}."
values={{
sampledValues,
sampledValuesFormatted: (
<strong data-test-subj={dataTestSubjDocsCount}>
{fieldFormats
.getDefaultInstance(KBN_FIELD_TYPES.NUMBER, [ES_FIELD_TYPES.INTEGER])
.convert(sampledValues)}
</strong>
),
}}
/>
);
} else {
labelElement =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('fieldStatsUtilsTextBased', function () {
expect(searchHandler).toHaveBeenCalledWith(
expect.objectContaining({
query:
'from logs* | limit 1000\n| WHERE `message` IS NOT NULL\n | STATS `message_terms` = count(`message`) BY `message`\n | SORT `message_terms` DESC\n | LIMIT 10',
'from logs* | limit 1000\n| WHERE `message` IS NOT NULL\n | STATS `message_terms` = count(mv_min(`message`)) BY `message`\n | SORT `message_terms` DESC\n | LIMIT 10',
})
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function getStringTopValues(
const esqlQuery = appendToESQLQuery(
esqlBaseQuery,
`| WHERE ${safeEsqlFieldName} IS NOT NULL
| STATS ${safeEsqlFieldNameTerms} = count(${safeEsqlFieldName}) BY ${safeEsqlFieldName}
| STATS ${safeEsqlFieldNameTerms} = count(mv_min(${safeEsqlFieldName})) BY ${safeEsqlFieldName}
| SORT ${safeEsqlFieldNameTerms} DESC
| LIMIT ${size}`
);
Expand All @@ -92,7 +92,7 @@ export async function getStringTopValues(
return {};
}

const sampledValues = values?.reduce((acc: number, row) => acc + row[0], 0);
const sampledDocuments = values?.reduce((acc: number, row) => acc + row[0], 0);

const topValues = {
buckets: values.map((value) => ({
Expand All @@ -102,9 +102,9 @@ export async function getStringTopValues(
};

return {
totalDocuments: sampledValues,
sampledDocuments: sampledValues,
sampledValues,
totalDocuments: sampledDocuments,
sampledDocuments,
sampledValues: sampledDocuments,
topValues,
};
}
Expand Down
12 changes: 6 additions & 6 deletions test/functional/apps/discover/group6/_sidebar_field_stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const topValuesRows = await testSubjects.findAll('dscFieldStats-topValues-bucket');
expect(topValuesRows.length).to.eql(10);
expect(await testSubjects.getVisibleText('dscFieldStats-statsFooter')).to.contain(
'42 sample values'
'42 sample records'
);

await PageObjects.unifiedFieldList.clickFieldListPlusFilter('bytes', '0');
Expand All @@ -186,7 +186,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await testSubjects.missingOrFail('unifiedFieldStats-buttonGroup');
await testSubjects.missingOrFail('unifiedFieldStats-histogram');
expect(await testSubjects.getVisibleText('dscFieldStats-statsFooter')).to.contain(
'500 sample values'
'500 sample records'
);

await PageObjects.unifiedFieldList.clickFieldListPlusFilter('extension.raw', 'css');
Expand All @@ -208,7 +208,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await testSubjects.missingOrFail('unifiedFieldStats-buttonGroup');
await testSubjects.missingOrFail('unifiedFieldStats-histogram');
expect(await testSubjects.getVisibleText('dscFieldStats-statsFooter')).to.contain(
'32 sample values'
'32 sample records'
);

await PageObjects.unifiedFieldList.clickFieldListPlusFilter('clientip', '216.126.255.31');
Expand All @@ -230,7 +230,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await testSubjects.missingOrFail('unifiedFieldStats-buttonGroup');
await testSubjects.missingOrFail('unifiedFieldStats-histogram');
expect(await testSubjects.getVisibleText('dscFieldStats-statsFooter')).to.contain(
'500 sample values'
'500 sample records'
);
await PageObjects.unifiedFieldList.closeFieldPopover();
});
Expand Down Expand Up @@ -310,7 +310,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const topValuesRows = await testSubjects.findAll('dscFieldStats-topValues-bucket');
expect(topValuesRows.length).to.eql(3);
expect(await testSubjects.getVisibleText('dscFieldStats-statsFooter')).to.contain(
'3 sample values'
'3 sample records'
);

await PageObjects.unifiedFieldList.clickFieldListPlusFilter('avg(bytes)', '5453');
Expand Down Expand Up @@ -339,7 +339,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
'true\n100%'
);
expect(await testSubjects.getVisibleText('dscFieldStats-statsFooter')).to.contain(
'1 sample value'
'1 sample record'
);

await PageObjects.unifiedFieldList.clickFieldListMinusFilter('enabled', 'true');
Expand Down