Merge pull request #5269 from epixa/5233-disallow-empty-msearch
Treat no index in msearch as empty instead of global
This commit is contained in:
commit
2041d9ae7a
2 changed files with 74 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,17 @@ define(function (require) {
|
|||
return indexList.toIndexList(timeBounds.min, timeBounds.max);
|
||||
})
|
||||
.then(function (indexList) {
|
||||
// If we've reached this point and there are no indexes in the
|
||||
// index list at all, it means that we shouldn't expect any indexes
|
||||
// to contain the documents we're looking for, so we instead
|
||||
// perform a request for an index pattern that we know will always
|
||||
// return an empty result (ie. -*). If instead we had gone ahead
|
||||
// with an msearch without any index patterns, elasticsearch would
|
||||
// handle that request by querying *all* indexes, which is the
|
||||
// opposite of what we want in this case.
|
||||
if (_.isArray(indexList) && indexList.length === 0) {
|
||||
indexList.push('-*');
|
||||
}
|
||||
return angular.toJson({
|
||||
index: indexList,
|
||||
type: fetchParams.type,
|
||||
|
|
Loading…
Reference in a new issue