mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Merge pull request #4109 from spalger/implement/discoverMaxSegments
[courier/segmentedFetch] allow limiting the number of segments fetched
This commit is contained in:
commit
61f7c1537c
2 changed files with 17 additions and 4 deletions
|
@ -46,6 +46,12 @@ define(function () {
|
|||
value: 500,
|
||||
description: 'The number of rows to show in the table',
|
||||
},
|
||||
'courier:maxSegmentCount': {
|
||||
value: 30,
|
||||
description: 'Requests in discover are split into segments to prevent massive requests from being sent to ' +
|
||||
'elasticsearch. This setting attempts to prevent the list of segments from getting too long, which might ' +
|
||||
'cause requests to take much longer to process.'
|
||||
},
|
||||
'fields:popularLimit': {
|
||||
value: 10,
|
||||
description: 'The top N most popular fields to show',
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
define(function (require) {
|
||||
return function CourierSegmentedReqProvider(es, Private, Promise, Notifier, timefilter) {
|
||||
return function CourierSegmentedReqProvider(es, Private, Promise, Notifier, timefilter, config) {
|
||||
var _ = require('lodash');
|
||||
var SearchReq = Private(require('components/courier/fetch/request/search'));
|
||||
var requestQueue = Private(require('components/courier/_request_queue'));
|
||||
|
@ -18,6 +18,7 @@ define(function (require) {
|
|||
// segmented request specific state
|
||||
this._initFn = initFn;
|
||||
this._desiredSize = false;
|
||||
this._maxSegments = config.get('courier:maxSegmentCount');
|
||||
this._hitsReceived = 0;
|
||||
this._direction = 'desc';
|
||||
this._handle = new SegmentedHandle(this);
|
||||
|
@ -67,9 +68,16 @@ define(function (require) {
|
|||
return self._getFlattenedSource()
|
||||
.then(function (flatSource) {
|
||||
var params = _.cloneDeep(flatSource);
|
||||
var index = self._active = self._queue.shift();
|
||||
|
||||
params.index = index;
|
||||
// calculate the number of indices to fetch in this request in order to prevent
|
||||
// more than self._maxSegments requests. We use Math.max(1, n) to ensure that each request
|
||||
// has at least one index pattern, and Math.floor() to make sure that if the
|
||||
// number of indices does not round out evenly the extra index is tacked onto the last
|
||||
// request, making sure the first request returns faster.
|
||||
var remainingSegments = self._maxSegments - self._segments.length;
|
||||
var indexCount = Math.max(1, Math.floor(self._queue.length / remainingSegments));
|
||||
params.index = self._active = self._queue.splice(0, indexCount);
|
||||
|
||||
if (self._desiredSize !== false) {
|
||||
params.body.size = Math.max(self._desiredSize - self._hitsReceived, 0);
|
||||
}
|
||||
|
@ -155,7 +163,6 @@ define(function (require) {
|
|||
total: this._all.length,
|
||||
complete: this._complete.length,
|
||||
remaining: this._queue.length,
|
||||
active: this._active,
|
||||
hitCount: this._mergedResp.hits.hits.length
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue