Skip to content
Draft
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
4 changes: 2 additions & 2 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ update_typo_tolerance_1: |-
reset_typo_tolerance_1: |-
client.index('books').resetTypoTolerance()
get_index_stats_1: |-
client.index('movies').getStats()
client.index('movies').getStats({ showInternalDatabaseSizes: true, sizeFormat: 'human' })
get_indexes_stats_1: |-
client.getStats()
client.getStats({ showInternalDatabaseSizes: true, sizeFormat: 'human' })
get_health_1: |-
client.health()
get_version_1: |-
Expand Down
6 changes: 5 additions & 1 deletion src/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
IndexObject,
IndexOptions,
IndexStats,
StatsParams,
DocumentsQuery,
DocumentQuery,
DocumentOptions,
Expand Down Expand Up @@ -285,11 +286,14 @@ export class Index<T extends RecordAny = RecordAny> {
/**
* Get stats of an index
*
* @param params - Optional parameters to control size formatting and
* internal database size reporting
* @returns Promise containing object with stats of the index
*/
async getStats(): Promise<IndexStats> {
async getStats(params?: StatsParams): Promise<IndexStats> {
return await this.httpRequest.get<IndexStats>({
path: `indexes/${this.uid}/stats`,
params,
});
}

Expand Down
7 changes: 5 additions & 2 deletions src/meilisearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
Key,
Health,
Stats,
StatsParams,
Version,
KeyUpdate,
IndexesQuery,
Expand Down Expand Up @@ -698,10 +699,12 @@ export class Meilisearch {
/**
* Get the stats of all the database
*
* @param params - Optional parameters to control size formatting and
* internal database size reporting
* @returns Promise returning object of all the stats
*/
async getStats(): Promise<Stats> {
return await this.httpRequest.get<Stats>({ path: "stats" });
async getStats(params?: StatsParams): Promise<Stats> {
return await this.httpRequest.get<Stats>({ path: "stats", params });
}

///
Expand Down
18 changes: 14 additions & 4 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,19 +746,29 @@ export type Health = {
*** STATS
*/

/** @see https://www.meilisearch.com/docs/reference/api/stats */
export type StatsParams = {
/** When true, index stat objects include an `internalDatabaseSizes` map of internal DB names to their sizes. */
showInternalDatabaseSizes?: boolean;
/** When `"human"`, all size fields are returned as human-readable strings (e.g. `"2.3 MiB"`); defaults to `"raw"` (numeric bytes). */
sizeFormat?: "raw" | "human";
};

export type IndexStats = {
numberOfDocuments: number;
isIndexing: boolean;
fieldDistribution: FieldDistribution;
numberOfEmbeddedDocuments: number;
numberOfEmbeddings: number;
rawDocumentDbSize: number;
avgDocumentSize: number;
rawDocumentDbSize: number | string;
avgDocumentSize: number | string;
/** Present only when `showInternalDatabaseSizes` is `true`. Keys are subject to change. */
internalDatabaseSizes?: Record<string, number | string>;
};

export type Stats = {
databaseSize: number;
usedDatabaseSize: number;
databaseSize: number | string;
usedDatabaseSize: number | string;
lastUpdate: string;
indexes: {
[index: string]: IndexStats;
Expand Down
Loading