From 3a7f27e91ce8e58c02de5f096aa360c80086d39f Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Wed, 18 Dec 2019 15:37:17 -0700 Subject: [PATCH] use max_inner_result_window to define top hits max --- .../es_search_source/es_search_source.js | 22 +------------- .../es_search_source/load_index_settings.js | 29 +++++++++++++++++++ .../es_search_source/update_source_editor.js | 19 ++++++++++-- 3 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index 926b272dbe3e1..828ea2ffeee40 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -17,37 +17,17 @@ import { UpdateSourceEditor } from './update_source_editor'; import { ES_SEARCH, ES_GEO_FIELD_TYPE, - DEFAULT_MAX_RESULT_WINDOW, - DEFAULT_MAX_INNER_RESULT_WINDOW, DEFAULT_MAX_BUCKETS_LIMIT, - GIS_API_PATH, SORT_ORDER, } from '../../../../common/constants'; import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; import { getSourceFields } from '../../../index_pattern_util'; -import { kfetch } from 'ui/kfetch'; +import { loadIndexSettings } from './load_index_settings'; import { DEFAULT_FILTER_BY_MAP_BOUNDS } from './constants'; import { ESDocField } from '../../fields/es_doc_field'; -async function loadIndexSettings(indexPatternTitle) { - try { - const indexSettings = await kfetch({ - pathname: `../${GIS_API_PATH}/indexSettings`, - query: { - indexPatternTitle, - }, - }); - return indexSettings; - } catch (err) { - return { - maxResultWindow: DEFAULT_MAX_RESULT_WINDOW, - maxInnerResultWindow: DEFAULT_MAX_INNER_RESULT_WINDOW, - }; - } -} - export class ESSearchSource extends AbstractESSource { static type = ES_SEARCH; static title = i18n.translate('xpack.maps.source.esSearchTitle', { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js new file mode 100644 index 0000000000000..2f3dd8e6df14d --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js @@ -0,0 +1,29 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { + DEFAULT_MAX_RESULT_WINDOW, + DEFAULT_MAX_INNER_RESULT_WINDOW, + GIS_API_PATH, +} from '../../../../common/constants'; +import { kfetch } from 'ui/kfetch'; + +export async function loadIndexSettings(indexPatternTitle) { + try { + const indexSettings = await kfetch({ + pathname: `../${GIS_API_PATH}/indexSettings`, + query: { + indexPatternTitle, + }, + }); + return indexSettings; + } catch (err) { + return { + maxResultWindow: DEFAULT_MAX_RESULT_WINDOW, + maxInnerResultWindow: DEFAULT_MAX_INNER_RESULT_WINDOW, + }; + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js index 595e1d0c755cf..4503856829ef2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js @@ -22,9 +22,10 @@ import { indexPatternService } from '../../../kibana_services'; import { i18n } from '@kbn/i18n'; import { getTermsFields, getSourceFields } from '../../../index_pattern_util'; import { ValidatedRange } from '../../../components/validated_range'; -import { SORT_ORDER } from '../../../../common/constants'; +import { DEFAULT_MAX_INNER_RESULT_WINDOW, SORT_ORDER } from '../../../../common/constants'; import { ESDocField } from '../../fields/es_doc_field'; import { FormattedMessage } from '@kbn/i18n/react'; +import { loadIndexSettings } from './load_index_settings'; export class UpdateSourceEditor extends Component { static propTypes = { @@ -43,17 +44,31 @@ export class UpdateSourceEditor extends Component { sourceFields: null, termFields: null, sortFields: null, + maxInnerResultWindow: DEFAULT_MAX_INNER_RESULT_WINDOW, }; componentDidMount() { this._isMounted = true; this.loadFields(); + this.loadIndexSettings(); } componentWillUnmount() { this._isMounted = false; } + async loadIndexSettings() { + try { + const indexPattern = await indexPatternService.get(this.props.indexPatternId); + const { maxInnerResultWindow } = await loadIndexSettings(indexPattern.title); + if (this._isMounted) { + this.setState({ maxInnerResultWindow }); + } + } catch (err) { + return; + } + } + async loadFields() { let indexPattern; try { @@ -149,7 +164,7 @@ export class UpdateSourceEditor extends Component { >