Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to enable frozen index search #27297

Merged
merged 4 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/management/advanced-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ document.
`discover:sort:defaultOrder`:: Controls the default sort direction for time based index patterns in the Discover app.
`doc_table:highlight`:: Highlight results in Discover and Saved Searches Dashboard. Highlighting makes request slow when
working on big documents. Set this property to `false` to disable highlighting.
`search:includeFrozen`:: Will include {ref}/frozen-indices.html[frozen indices] in results if enabled. Searching through frozen indices
might increase the search time.
`courier:maxSegmentCount`:: Kibana splits requests in the Discover app into segments to limit the size of requests sent to
the Elasticsearch cluster. This setting constrains the length of the segment list. Long segment lists can significantly
increase request processing time.
Expand Down
8 changes: 8 additions & 0 deletions src/legacy/core_plugins/kibana/ui_setting_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ export function getUiSettingDefaults() {
}),
category: ['search'],
},
'search:includeFrozen': {
name: 'Search in frozen indices',
description: `Will include <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/frozen-indices.html"
target="_blank" rel="noopener noreferrer">frozen indices</a> in results if enabled. Searching through frozen indices
might increase the search time.`,
value: false,
category: ['search'],
},
'fields:popularLimit': {
name: i18n.translate('kbn.advancedSettings.fieldsPopularLimitTitle', {
defaultMessage: 'Popular fields limit',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export default async (req, panel) => {

if (!bodies.length) return { responses: [] };
try {
const includeFrozen = await req.getUiSettingsService().get('search:includeFrozen');
const resp = await callWithRequest(req, 'msearch', {
ignore_throttled: !includeFrozen,
rest_total_hits_as_int: true,
body: bodies.reduce((acc, item) => acc.concat(item), [])
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import getRequestParams from './series/get_request_params';
import handleResponseBody from './series/handle_response_body';
import handleErrorResponse from './handle_error_response';
import getAnnotations from './get_annotations';
export function getSeriesData(req, panel) {
export async function getSeriesData(req, panel) {
const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('data');
const includeFrozen = await req.getUiSettingsService().get('search:includeFrozen');
const bodies = panel.series.map(series => getRequestParams(req, panel, series));
const params = {
rest_total_hits_as_int: true,
ignore_throttled: !includeFrozen,
body: bodies.reduce((acc, items) => acc.concat(items), [])
};
return callWithRequest(req, 'msearch', params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import { get } from 'lodash';
import processBucket from './table/process_bucket';
export async function getTableData(req, panel) {
const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('data');
const includeFrozen = await req.getUiSettingsService().get('search:includeFrozen');
const params = {
index: panel.index_pattern,
ignore_throttled: !includeFrozen,
body: buildRequestBody(req, panel)
};
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ describe(filename, () => {
});

describe('timeouts', () => {

let sandbox;

beforeEach(() => {
Expand All @@ -225,6 +224,34 @@ describe(filename, () => {
});
});

describe('frozen indices', () => {
let sandbox;

beforeEach(() => {
sandbox = sinon.createSandbox();
});

afterEach(() => {
sandbox.restore();
});

it('sets ignore_throttled=true on the request', () => {
config.index = 'beer';
tlConfig.settings['search:includeFrozen'] = false;
const request = fn(config, tlConfig, emptyScriptedFields);

expect(request.ignore_throttled).to.equal(true);
});

it('sets no timeout if elasticsearch.shardTimeout is set to 0', () => {
tlConfig.settings['search:includeFrozen'] = true;
config.index = 'beer';
const request = fn(config, tlConfig, emptyScriptedFields);

expect(request.ignore_throttled).to.equal(false);
});
});

describe('query body', () => {
beforeEach(() => {
tlConfig = _.merge(tlConfigFn(), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default function buildRequest(config, tlConfig, scriptedFields) {

const request = {
index: config.index,
ignore_throttled: !tlConfig.settings['search:includeFrozen'],
body: {
query: {
bool: bool
Expand Down
3 changes: 2 additions & 1 deletion src/ui/public/courier/fetch/call_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function CallClientProvider(Private, Promise, es, config) {

function callClient(searchRequests) {
const maxConcurrentShardRequests = config.get('courier:maxConcurrentShardRequests');
const includeFrozen = config.get('search:includeFrozen');

// merging docs can change status to DUPLICATE, capture new statuses
const searchRequestsAndStatuses = mergeDuplicateRequests(searchRequests);
Expand Down Expand Up @@ -143,7 +144,7 @@ export function CallClientProvider(Private, Promise, es, config) {
searching,
abort,
failedSearchRequests,
} = await searchStrategy.search({ searchRequests, es, Promise, serializeFetchParams, maxConcurrentShardRequests });
} = await searchStrategy.search({ searchRequests, es, Promise, serializeFetchParams, includeFrozen, maxConcurrentShardRequests });

// Collect searchRequests which have successfully been sent.
searchRequests.forEach(searchRequest => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function serializeAllFetchParams(fetchParams, searchRequests, serializeFet
export const defaultSearchStrategy = {
id: 'default',

search: async ({ searchRequests, es, Promise, serializeFetchParams, maxConcurrentShardRequests = 0 }) => {
search: async ({ searchRequests, es, Promise, serializeFetchParams, includeFrozen = false, maxConcurrentShardRequests = 0 }) => {
// Flatten the searchSource within each searchRequest to get the fetch params,
// e.g. body, filters, index pattern, query.
const allFetchParams = await getAllFetchParams(searchRequests, Promise);
Expand All @@ -70,6 +70,8 @@ export const defaultSearchStrategy = {

const msearchParams = {
rest_total_hits_as_int: true,
// If we want to include frozen indexes we need to specify ignore_throttled: false
ignore_throttled: !includeFrozen,
body: serializedFetchParams,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ describe('defaultSearchStrategy', function () {
expect(searchArgs.es.msearch.mock.calls[0][0]).toHaveProperty('rest_total_hits_as_int', true);
});

test('should set ignore_throttled=false when including frozen indices', async () => {
await search({ ...searchArgs, includeFrozen: true });
expect(searchArgs.es.msearch.mock.calls[0][0]).toHaveProperty('ignore_throttled', false);
});

});

});
4 changes: 2 additions & 2 deletions x-pack/plugins/graph/server/lib/es/call_es_search_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

import Boom from 'boom';

export async function callEsSearchApi({ callCluster, index, body }) {
export async function callEsSearchApi({ callCluster, index, body, queryParams }) {
try {
return {
ok: true,
resp: await callCluster('search', {
rest_total_hits_as_int: true,
...queryParams,
index,
body
})
Expand Down
11 changes: 8 additions & 3 deletions x-pack/plugins/graph/server/routes/search_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ export const searchProxyRoute = {
body: Joi.object().unknown(true).default()
}).default()
},
handler(request) {
return callEsSearchApi({
async handler(request) {
const includeFrozen = await request.getUiSettingsService().get('search:includeFrozen');
return await callEsSearchApi({
callCluster: request.pre.callCluster,
index: request.payload.index,
body: request.payload.body
body: request.payload.body,
queryParams: {
rest_total_hits_as_int: true,
ignore_throttled: !includeFrozen,
}
});
}
}
Expand Down