Skip to content

Commit

Permalink
feat: Add support for track_total_hits (sudo-suhas#96)
Browse files Browse the repository at this point in the history
Add method to specify parameter on request body search instance.

Feature was added to elasticsearch in 7.x - 
https://www.elastic.co/guide/en/elasticsearch/reference/7.3/search-request-body.html#request-body-search-track-total-hits
  • Loading branch information
lostpebble authored and sudo-suhas committed Aug 6, 2019
1 parent 88595dd commit fdf74c0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/core/request-body-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
11 changes: 11 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
1 change: 1 addition & 0 deletions test/core-test/request-body-search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down

0 comments on commit fdf74c0

Please sign in to comment.