diff --git a/src/core/request-body-search.js b/src/core/request-body-search.js index 384bfb83..c1a90d11 100644 --- a/src/core/request-body-search.js +++ b/src/core/request-body-search.js @@ -315,6 +315,21 @@ class RequestBodySearch { return this; } + /** + * 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 (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..9828b6c0 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -134,6 +134,17 @@ 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. Passing `false` can increase performance in some situations. + * (Added in elasticsearch@7) + * + * 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', {