diff --git a/doc/7/controllers/index/stats/index.md b/doc/7/controllers/index/stats/index.md
new file mode 100644
index 000000000..b28888954
--- /dev/null
+++ b/doc/7/controllers/index/stats/index.md
@@ -0,0 +1,41 @@
+---
+code: true
+type: page
+title: stats
+description: Gets detailed storage statistics
+---
+
+# stats
+
+
+
+
+Gets detailed storage usage statistics.
+
+
+
+```js
+stats([options]);
+```
+
+
+
+| Arguments | Type | Description |
+| --------- | ----------------- | ------------- |
+| `options` |
object
| Query options |
+
+### options
+
+Additional query options
+
+| Property | Type
(default) | Description |
+| ---------- | ------------------------------- | ---------------------------------------------------------------------------- |
+| `queuable` | boolean
(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |
+
+## Resolves
+
+Returns detailed storage usage statistics: overall index/collection sizes and the number of documents per collection.
+
+## Usage
+
+<<< ./snippets/stats.js
diff --git a/doc/7/controllers/index/stats/snippets/stats.js b/doc/7/controllers/index/stats/snippets/stats.js
new file mode 100644
index 000000000..ca75ccb33
--- /dev/null
+++ b/doc/7/controllers/index/stats/snippets/stats.js
@@ -0,0 +1,21 @@
+const stats = await kuzzle.index.stats();
+
+console.log(JSON.stringify(stats));
+/*
+ {
+ "indexes":[
+ {
+ "name":"nyc-open-data",
+ "size":42,
+ "collections":[
+ {
+ "name":"yellow-taxi",
+ "documentCount":42,
+ "size":42
+ }
+ ]
+ }
+ ],
+ "size":42
+ }
+*/
diff --git a/doc/7/controllers/index/stats/snippets/stats.test.yml b/doc/7/controllers/index/stats/snippets/stats.test.yml
new file mode 100644
index 000000000..abf725fa9
--- /dev/null
+++ b/doc/7/controllers/index/stats/snippets/stats.test.yml
@@ -0,0 +1,10 @@
+---
+name: index#stats
+description: Gets detailed storage statistics
+hooks:
+ before: |
+ curl -X POST kuzzle:7512/nyc-open-data/_create
+ curl -XPUT kuzzle:7512/nyc-open-data/yellow-taxi
+ after: curl -X DELETE kuzzle:7512/nyc-open-data
+template: catch
+expected: ["documentCount":0]
diff --git a/src/controllers/Index.ts b/src/controllers/Index.ts
index 61fc13c10..e2fabafef 100644
--- a/src/controllers/Index.ts
+++ b/src/controllers/Index.ts
@@ -1,4 +1,5 @@
import { BaseController } from './Base';
+import { JSONObject } from '../types';
export class IndexController extends BaseController {
@@ -99,4 +100,19 @@ export class IndexController extends BaseController {
return this.query(request, options)
.then(response => response.result.deleted);
}
+
+ /**
+ * Returns detailed storage usage statistics.
+ *
+ * @see https://docs.kuzzle.io/sdk/js/7/controllers/index/stats/
+ *
+ * @param options Additional options
+ * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again
+ */
+ stats (options: { queuable?: boolean } = {}): Promise {
+ return this.query({
+ action: 'stats'
+ }, options)
+ .then(response => response.result);
+ }
}
diff --git a/test/controllers/index.test.js b/test/controllers/index.test.js
index 8bd2e901a..a76c45f0d 100644
--- a/test/controllers/index.test.js
+++ b/test/controllers/index.test.js
@@ -120,4 +120,37 @@ describe('Index Controller', () => {
});
});
});
+
+ describe('stats', () => {
+ it('should call index/stats query and return a Promise which resolves to an object containing detailed storage statistics', () => {
+ const result = {
+ indexes: [
+ {
+ name: 'nyc-open-data',
+ size: 42,
+ collections: [
+ {
+ name: 'yellow-taxi',
+ documentCount: 42,
+ size: 42,
+ }
+ ]
+ }
+ ]
+ };
+ kuzzle.query.resolves({result});
+
+ return kuzzle.index.stats(options)
+ .then(res => {
+ should(kuzzle.query)
+ .be.calledOnce()
+ .be.calledWith({
+ controller: 'index',
+ action: 'stats'
+ }, options);
+
+ should(res).be.equal(result);
+ });
+ });
+ });
});