Skip to content

Commit

Permalink
Merge pull request elastic#7286 from epixa/7283-kibanadevnull
Browse files Browse the repository at this point in the history
Query no matches on .kibana instead of .kibana-devnull
  • Loading branch information
epixa authored Jul 14, 2016
2 parents 6bcaa1c + 482909a commit a9abb0e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/ui/public/courier/fetch/strategy/__tests__/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,21 @@ describe('ui/courier/fetch/strategy/search', () => {
context('when indexList is empty', () => {
beforeEach(() => reqsFetchParams[0].index = []);

it('queries .kibana-devnull instead', () => {
it('queries the kibana index (.kibana) with a must_not match_all boolean', () => {
const query = JSON.stringify({
query: {
bool: {
must_not: [
{ match_all: {} }
]
}
}
});
let value;
search.reqsFetchParamsToBody(reqsFetchParams).then(val => value = val);
$rootScope.$apply();
expect(_.includes(value, '"index":[".kibana-devnull"]')).to.be(true);
expect(_.includes(value, '"index":[".kibana"]')).to.be(true);
expect(_.includes(value, query)).to.be(true);
});
});
});
Expand Down
20 changes: 17 additions & 3 deletions src/ui/public/courier/fetch/strategy/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import angular from 'angular';

import { toJson } from 'ui/utils/aggressive_parse';

export default function FetchStrategyForSearch(Private, Promise, timefilter) {
export default function FetchStrategyForSearch(Private, Promise, timefilter, kbnIndex) {

return {
clientMethod: 'msearch',
Expand All @@ -26,6 +26,7 @@ export default function FetchStrategyForSearch(Private, Promise, timefilter) {
return indexList.toIndexList(timeBounds.min, timeBounds.max);
})
.then(function (indexList) {
let body = fetchParams.body || {};
// 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
Expand All @@ -35,7 +36,8 @@ export default function FetchStrategyForSearch(Private, Promise, timefilter) {
// 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('.kibana-devnull');
indexList.push(kbnIndex);
body = emptySearch();
}
return angular.toJson({
index: indexList,
Expand All @@ -44,7 +46,7 @@ export default function FetchStrategyForSearch(Private, Promise, timefilter) {
ignore_unavailable: true
})
+ '\n'
+ toJson(fetchParams.body || {}, angular.toJson);
+ toJson(body, angular.toJson);
});
})
.then(function (requests) {
Expand All @@ -62,3 +64,15 @@ export default function FetchStrategyForSearch(Private, Promise, timefilter) {
}
};
};

function emptySearch() {
return {
query: {
bool: {
must_not: [
{ match_all: {} }
]
}
}
};
}

0 comments on commit a9abb0e

Please sign in to comment.