Skip to content

Commit

Permalink
use max_inner_result_window to define top hits max
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Dec 18, 2019
1 parent 2c7fb06 commit 3a7f27e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 {
Expand Down Expand Up @@ -149,7 +164,7 @@ export class UpdateSourceEditor extends Component {
>
<ValidatedRange
min={1}
max={100}
max={this.state.maxInnerResultWindow}
step={1}
value={this.props.topHitsSize}
onChange={this.onTopHitsSizeChange}
Expand Down

0 comments on commit 3a7f27e

Please sign in to comment.