Skip to content

Commit

Permalink
Update courier inspector stats to handle total object format (#93703)
Browse files Browse the repository at this point in the history
* Update courier inspector stats to handle total object format

* tslint

* add TODO comment

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
nreese and kibanamachine committed Mar 10, 2021
1 parent cce4db8 commit c9e81be
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,27 @@ export function getResponseInspectorStats(
};
}

if (resp && resp.hits) {
if (resp && resp.hits?.total !== undefined) {
let value: string | undefined;
// TODO remove case where total is number when legacyHitsTotal is removed
if (typeof resp.hits.total === 'number') {
value = `${resp.hits.total}`;
} else {
const total = resp.hits.total as { relation: string; value: number };
value = total.relation === 'eq' ? `${total.value}` : `> ${total.value}`;
}
stats.hitsTotal = {
label: i18n.translate('data.search.searchSource.hitsTotalLabel', {
defaultMessage: 'Hits (total)',
}),
value: `${resp.hits.total}`,
value,
description: i18n.translate('data.search.searchSource.hitsTotalDescription', {
defaultMessage: 'The number of documents that match the query.',
}),
};
}

if (resp && resp.hits) {
stats.hits = {
label: i18n.translate('data.search.searchSource.hitsLabel', {
defaultMessage: 'Hits',
Expand Down

0 comments on commit c9e81be

Please sign in to comment.