Treat no index in msearch as empty instead of global
Prior to this, if you were to pass an empty index list to the search fetch strategy in courier, kibana would perform an msearch on all indexes in elasticsearch. This commit implements the desired behavior that no defined index list means there are no indexes to query, and thus is treated like an empty response.
This commit is contained in:
parent
269fb36e5c
commit
62a93487dd
2 changed files with 66 additions and 0 deletions
63
src/ui/public/courier/fetch/strategy/__tests__/search.js
Normal file
63
src/ui/public/courier/fetch/strategy/__tests__/search.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
describe('ui/courier/fetch/strategy/search', () => {
|
||||
const _ = require('lodash');
|
||||
const sinon = require('auto-release-sinon');
|
||||
const expect = require('expect.js');
|
||||
const ngMock = require('ngMock');
|
||||
|
||||
let Promise;
|
||||
let $rootScope;
|
||||
let search;
|
||||
let reqsFetchParams;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
|
||||
beforeEach(ngMock.inject((Private, $injector) => {
|
||||
Promise = $injector.get('Promise');
|
||||
$rootScope = $injector.get('$rootScope');
|
||||
search = Private(require('ui/courier/fetch/strategy/search'));
|
||||
reqsFetchParams = [
|
||||
{
|
||||
index: ['logstash-123'],
|
||||
type: 'blah',
|
||||
search_type: 'blah2',
|
||||
body: 'hm this is the body'
|
||||
}
|
||||
];
|
||||
}));
|
||||
|
||||
describe('#clientMethod', () => {
|
||||
it('is msearch', () => {
|
||||
expect(search.clientMethod).to.equal('msearch');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#reqsFetchParamsToBody()', () => {
|
||||
context('when indexList is not empty', () => {
|
||||
it('includes the index', () => {
|
||||
let value;
|
||||
search.reqsFetchParamsToBody(reqsFetchParams).then(val => value = val);
|
||||
$rootScope.$apply();
|
||||
expect(_.includes(value, '"index":["logstash-123"]')).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
context('when indexList is empty', () => {
|
||||
beforeEach(() => reqsFetchParams[0].index = []);
|
||||
|
||||
it('explicitly negates any indexes', () => {
|
||||
let value;
|
||||
search.reqsFetchParamsToBody(reqsFetchParams).then(val => value = val);
|
||||
$rootScope.$apply();
|
||||
expect(_.includes(value, '"index":["-*"]')).to.be(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getResponses()', () => {
|
||||
it('returns the `responses` property of the given arg', () => {
|
||||
const responses = [{}];
|
||||
const returned = search.getResponses({ responses });
|
||||
expect(returned).to.be(responses);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -24,6 +24,9 @@ define(function (require) {
|
|||
return indexList.toIndexList(timeBounds.min, timeBounds.max);
|
||||
})
|
||||
.then(function (indexList) {
|
||||
if (_.isArray(indexList) && indexList.length === 0) {
|
||||
indexList.push('-*');
|
||||
}
|
||||
return angular.toJson({
|
||||
index: indexList,
|
||||
type: fetchParams.type,
|
||||
|
|
Loading…
Reference in a new issue