Skip to content

Commit f868a39

Browse files
committed
Remove the unsupported optional limit argument
ReadableSearch has an optional limit argument to limit the number of records streamed. It is now the responsibility of the query executor to enforce that limit. Example added to the Readme
1 parent dfd5de9 commit f868a39

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ ws._write = function(chunk, enc, next) {
5656
rs.pipe(ws);
5757
```
5858

59+
If we want to start the stream at an offset and define a limit:
60+
61+
```
62+
var offset = 7;
63+
var limit = 21;
64+
var page = 12;
65+
66+
var searchExec = function searchExec(from, callback) {
67+
client.search({
68+
index: 'myindex',
69+
from: from + offset,
70+
size: (offset + from + page) > limit ? (limit - offset - from) : page,
71+
body: {
72+
query: { match_all: {} }
73+
}
74+
}, callback);
75+
};
76+
```
77+
5978
## Stream scroll/scan results from Elasticsearch
6079
```
6180
var scrollExec = function scrollExec(from, callback) {

lib/readable-search.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@ module.exports = ReadableHits;
1212

1313
/**
1414
* @param queryExec an executable query functions that takes 2 arguments: the offset and a callback.
15-
* @param limit optional number of hits to stream
1615
*/
17-
function ReadableHits(queryExec, limit) {
16+
function ReadableHits(queryExec) {
1817
Readable.call(this, {objectMode:true});
1918
this.queryExec = queryExec;
2019
this.total = -1;
2120
this.from = 0;
2221
this._next = true;
23-
if (limit > 0) {
24-
this.limit = limit;
25-
}
2622

2723
// current iteration through the page
2824
this._hits = [];

0 commit comments

Comments
 (0)