From e09bf784032c62b2d756a13509fc6b46d32ecb57 Mon Sep 17 00:00:00 2001 From: Paul Myburgh Date: Mon, 5 Aug 2019 18:32:23 +0200 Subject: [PATCH 1/2] feat: add support for `track_total_hits` --- src/core/request-body-search.js | 14 ++++++++++++++ src/index.d.ts | 9 +++++++++ test/core-test/request-body-search.test.js | 1 + 3 files changed, 24 insertions(+) diff --git a/src/core/request-body-search.js b/src/core/request-body-search.js index 384bfb83..e220b38c 100644 --- a/src/core/request-body-search.js +++ b/src/core/request-body-search.js @@ -315,6 +315,20 @@ class RequestBodySearch { return this; } + /** + * The `track_total_hits` parameter allows you to control how the total number of hits + * should be tracked. + * + * Pass `true`, `false`, or the upper limit (default: `10000`) of hits you want tracked. + * + * @param {boolean|number} enableOrLimit + * @returns {RequestBodySearch} returns `this` so that calls can be chained + */ + trackTotalHits(enableOrLimit) { + this._body.track_total_hits = enableOrLimit; + return this; + } + /** * Allows to control how the `_source` field is returned with every hit. * You can turn off `_source` retrieval by passing `false`. diff --git a/src/index.d.ts b/src/index.d.ts index 9a63c8b0..afdadddb 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -134,6 +134,15 @@ declare namespace esb { */ trackScores(enable: boolean): this; + /** + * The track_total_hits parameter allows you to control how the total number of hits should be tracked. + * + * Pass true, false, or the upper limit of hits you want tracked. + * + * @param {boolean|number} enable + */ + trackTotalHits(enable: boolean|number): this; + /** * Allows to control how the `_source` field is returned with every hit. * You can turn off `_source` retrieval by passing `false`. diff --git a/test/core-test/request-body-search.test.js b/test/core-test/request-body-search.test.js index bae9c68c..a6567f04 100644 --- a/test/core-test/request-body-search.test.js +++ b/test/core-test/request-body-search.test.js @@ -98,6 +98,7 @@ test(setsOption, 'sorts', { keyName: 'sort' }); test(setsOption, 'trackScores', { param: true }); +test(setsOption, 'trackTotalHits', { param: true }); test(setsOption, 'version', { param: true }); test(setsOption, 'explain', { param: true }); test(setsOption, 'highlight', { From 41d31804d1a02e8a2bbd354de66c2cb042e0a115 Mon Sep 17 00:00:00 2001 From: Paul Myburgh Date: Tue, 6 Aug 2019 09:42:25 +0200 Subject: [PATCH 2/2] feat: add support for `track_total_hits` - updated jsdoc comments --- src/core/request-body-search.js | 3 ++- src/index.d.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/request-body-search.js b/src/core/request-body-search.js index e220b38c..c1a90d11 100644 --- a/src/core/request-body-search.js +++ b/src/core/request-body-search.js @@ -317,7 +317,8 @@ class RequestBodySearch { /** * The `track_total_hits` parameter allows you to control how the total number of hits - * should be tracked. + * should be tracked. Passing `false` can increase performance in some situations. + * (Added in elasticsearch@7) * * Pass `true`, `false`, or the upper limit (default: `10000`) of hits you want tracked. * diff --git a/src/index.d.ts b/src/index.d.ts index afdadddb..9828b6c0 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -135,7 +135,9 @@ declare namespace esb { trackScores(enable: boolean): this; /** - * The track_total_hits parameter allows you to control how the total number of hits should be tracked. + * The `track_total_hits` parameter allows you to control how the total number of hits + * should be tracked. Passing `false` can increase performance in some situations. + * (Added in elasticsearch@7) * * Pass true, false, or the upper limit of hits you want tracked. *