Skip to content

Commit 2295dd0

Browse files
Merge branch 'master' into ftr/reorganize--page-objects
2 parents 620d7dd + d9554ff commit 2295dd0

File tree

30 files changed

+5624
-5062
lines changed

30 files changed

+5624
-5062
lines changed

docs/maps/maps-aggregations.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ To enable top hits:
4747
. Set *Entity* to the field that identifies entities in your documents.
4848
This field will be used in the terms aggregation to group your documents into entity buckets.
4949
. Set *Documents per entity* to configure the maximum number of documents accumulated per entity.
50+
This setting is limited to the `index.max_inner_result_window` index setting, which defaults to 100.
5051

5152
[role="screenshot"]
5253
image::maps/images/top_hits.png[]

docs/maps/vector-layer.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ See map.regionmap.* in <<settings>> for details.
1515
*Documents*:: Vector data from a Kibana index pattern.
1616
The index must contain at least one field mapped as {ref}/geo-point.html[geo_point] or {ref}/geo-shape.html[geo_shape].
1717

18-
NOTE: Document results are limited to the first 10000 matching documents.
18+
NOTE: Document results are limited to the `index.max_result_window` index setting, which defaults to 10000.
1919
Use <<maps-aggregations, aggregations>> to plot large data sets.
2020

2121
*Grid aggregation*:: Geospatial data grouped in grids with metrics for each gridded cell.

x-pack/legacy/plugins/maps/common/constants.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const APP_ICON = 'gisApp';
2626

2727
export const MAP_APP_PATH = `app/${APP_ID}`;
2828
export const GIS_API_PATH = `api/${APP_ID}`;
29+
export const INDEX_SETTINGS_API_PATH = `${GIS_API_PATH}/indexSettings`;
2930

3031
export const MAP_BASE_URL = `/${MAP_APP_PATH}#/${MAP_SAVED_OBJECT_TYPE}`;
3132

@@ -69,7 +70,9 @@ export const MAX_ZOOM = 24;
6970

7071
export const DECIMAL_DEGREES_PRECISION = 5; // meters precision
7172
export const ZOOM_PRECISION = 2;
72-
export const ES_SIZE_LIMIT = 10000;
73+
export const DEFAULT_MAX_RESULT_WINDOW = 10000;
74+
export const DEFAULT_MAX_INNER_RESULT_WINDOW = 100;
75+
export const DEFAULT_MAX_BUCKETS_LIMIT = 10000;
7376

7477
export const FEATURE_ID_PROPERTY_NAME = '__kbn__feature_id__';
7578
export const FEATURE_VISIBLE_PROPERTY_NAME = '__kbn_isvisibleduetojoin__';

x-pack/legacy/plugins/maps/public/layers/sources/client_file_source/geojson_file_source.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
import { AbstractVectorSource } from '../vector_source';
88
import React from 'react';
9-
import { ES_GEO_FIELD_TYPE, GEOJSON_FILE, ES_SIZE_LIMIT } from '../../../../common/constants';
9+
import {
10+
ES_GEO_FIELD_TYPE,
11+
GEOJSON_FILE,
12+
DEFAULT_MAX_RESULT_WINDOW,
13+
} from '../../../../common/constants';
1014
import { ClientFileCreateSourceEditor } from './create_client_file_source_editor';
1115
import { ESSearchSource } from '../es_search_source';
1216
import uuid from 'uuid/v4';
@@ -82,7 +86,7 @@ export class GeojsonFileSource extends AbstractVectorSource {
8286
addAndViewSource(null);
8387
} else {
8488
// Only turn on bounds filter for large doc counts
85-
const filterByMapBounds = indexDataResp.docCount > ES_SIZE_LIMIT;
89+
const filterByMapBounds = indexDataResp.docCount > DEFAULT_MAX_RESULT_WINDOW;
8690
const source = new ESSearchSource(
8791
{
8892
id: uuid(),

x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import { NoIndexPatternCallout } from '../../../components/no_index_pattern_call
1515
import { FormattedMessage } from '@kbn/i18n/react';
1616
import { i18n } from '@kbn/i18n';
1717
import { kfetch } from 'ui/kfetch';
18-
import { ES_GEO_FIELD_TYPE, GIS_API_PATH, ES_SIZE_LIMIT } from '../../../../common/constants';
18+
import {
19+
ES_GEO_FIELD_TYPE,
20+
GIS_API_PATH,
21+
DEFAULT_MAX_RESULT_WINDOW,
22+
} from '../../../../common/constants';
1923
import { DEFAULT_FILTER_BY_MAP_BOUNDS } from './constants';
2024

2125
import { npStart } from 'ui/new_platform';
@@ -96,7 +100,7 @@ export class CreateSourceEditor extends Component {
96100
let indexHasSmallDocCount = false;
97101
try {
98102
const indexDocCount = await this.loadIndexDocCount(indexPattern.title);
99-
indexHasSmallDocCount = indexDocCount <= ES_SIZE_LIMIT;
103+
indexHasSmallDocCount = indexDocCount <= DEFAULT_MAX_RESULT_WINDOW;
100104
} catch (error) {
101105
// retrieving index count is a nice to have and is not essential
102106
// do not interrupt user flow if unable to retrieve count

x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ import { UpdateSourceEditor } from './update_source_editor';
1717
import {
1818
ES_SEARCH,
1919
ES_GEO_FIELD_TYPE,
20-
ES_SIZE_LIMIT,
20+
DEFAULT_MAX_BUCKETS_LIMIT,
2121
SORT_ORDER,
2222
} from '../../../../common/constants';
2323
import { i18n } from '@kbn/i18n';
2424
import { getDataSourceLabel } from '../../../../common/i18n_getters';
2525
import { getSourceFields } from '../../../index_pattern_util';
26+
import { loadIndexSettings } from './load_index_settings';
2627

2728
import { DEFAULT_FILTER_BY_MAP_BOUNDS } from './constants';
2829
import { ESDocField } from '../../fields/es_doc_field';
@@ -267,8 +268,8 @@ export class ESSearchSource extends AbstractESSource {
267268
entitySplit: {
268269
terms: {
269270
field: topHitsSplitField,
270-
size: ES_SIZE_LIMIT,
271-
shard_size: ES_SIZE_LIMIT,
271+
size: DEFAULT_MAX_BUCKETS_LIMIT,
272+
shard_size: DEFAULT_MAX_BUCKETS_LIMIT,
272273
},
273274
aggs: {
274275
entityHits: {
@@ -290,7 +291,7 @@ export class ESSearchSource extends AbstractESSource {
290291
const entityBuckets = _.get(resp, 'aggregations.entitySplit.buckets', []);
291292
const totalEntities = _.get(resp, 'aggregations.totalEntities.value', 0);
292293
// can not compare entityBuckets.length to totalEntities because totalEntities is an approximate
293-
const areEntitiesTrimmed = entityBuckets.length >= ES_SIZE_LIMIT;
294+
const areEntitiesTrimmed = entityBuckets.length >= DEFAULT_MAX_BUCKETS_LIMIT;
294295
let areTopHitsTrimmed = false;
295296
entityBuckets.forEach(entityBucket => {
296297
const total = _.get(entityBucket, 'entityHits.hits.total', 0);
@@ -315,7 +316,7 @@ export class ESSearchSource extends AbstractESSource {
315316

316317
// searchFilters.fieldNames contains geo field and any fields needed for styling features
317318
// Performs Elasticsearch search request being careful to pull back only required fields to minimize response size
318-
async _getSearchHits(layerName, searchFilters, registerCancelCallback) {
319+
async _getSearchHits(layerName, searchFilters, maxResultWindow, registerCancelCallback) {
319320
const initialSearchContext = {
320321
docvalue_fields: await this._getDateDocvalueFields(searchFilters.fieldNames),
321322
};
@@ -331,7 +332,7 @@ export class ESSearchSource extends AbstractESSource {
331332
);
332333
searchSource = await this._makeSearchSource(
333334
searchFilters,
334-
ES_SIZE_LIMIT,
335+
maxResultWindow,
335336
initialSearchContext
336337
);
337338
searchSource.setField('source', false); // do not need anything from _source
@@ -340,7 +341,7 @@ export class ESSearchSource extends AbstractESSource {
340341
// geo_shape fields do not support docvalue_fields yet, so still have to be pulled from _source
341342
searchSource = await this._makeSearchSource(
342343
searchFilters,
343-
ES_SIZE_LIMIT,
344+
maxResultWindow,
344345
initialSearchContext
345346
);
346347
// Setting "fields" instead of "source: { includes: []}"
@@ -382,11 +383,19 @@ export class ESSearchSource extends AbstractESSource {
382383
}
383384

384385
async getGeoJsonWithMeta(layerName, searchFilters, registerCancelCallback) {
386+
const indexPattern = await this.getIndexPattern();
387+
388+
const indexSettings = await loadIndexSettings(indexPattern.title);
389+
385390
const { hits, meta } = this._isTopHits()
386391
? await this._getTopHits(layerName, searchFilters, registerCancelCallback)
387-
: await this._getSearchHits(layerName, searchFilters, registerCancelCallback);
392+
: await this._getSearchHits(
393+
layerName,
394+
searchFilters,
395+
indexSettings.maxResultWindow,
396+
registerCancelCallback
397+
);
388398

389-
const indexPattern = await this.getIndexPattern();
390399
const unusedMetaFields = indexPattern.metaFields.filter(metaField => {
391400
return !['_id', '_index'].includes(metaField);
392401
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import {
8+
DEFAULT_MAX_RESULT_WINDOW,
9+
DEFAULT_MAX_INNER_RESULT_WINDOW,
10+
INDEX_SETTINGS_API_PATH,
11+
} from '../../../../common/constants';
12+
import { kfetch } from 'ui/kfetch';
13+
import { toastNotifications } from 'ui/notify';
14+
import { i18n } from '@kbn/i18n';
15+
16+
let toastDisplayed = false;
17+
const indexSettings = new Map();
18+
19+
export async function loadIndexSettings(indexPatternTitle) {
20+
if (indexSettings.has(indexPatternTitle)) {
21+
return indexSettings.get(indexPatternTitle);
22+
}
23+
24+
const fetchPromise = fetchIndexSettings(indexPatternTitle);
25+
indexSettings.set(indexPatternTitle, fetchPromise);
26+
return fetchPromise;
27+
}
28+
29+
async function fetchIndexSettings(indexPatternTitle) {
30+
try {
31+
const indexSettings = await kfetch({
32+
pathname: `../${INDEX_SETTINGS_API_PATH}`,
33+
query: {
34+
indexPatternTitle,
35+
},
36+
});
37+
return indexSettings;
38+
} catch (err) {
39+
const warningMsg = i18n.translate('xpack.maps.indexSettings.fetchErrorMsg', {
40+
defaultMessage: `Unable to fetch index settings for index pattern '{indexPatternTitle}'.
41+
Ensure you have '{viewIndexMetaRole}' role.`,
42+
values: {
43+
indexPatternTitle,
44+
viewIndexMetaRole: 'view_index_metadata',
45+
},
46+
});
47+
if (!toastDisplayed) {
48+
// Only show toast for first failure to avoid flooding user with warnings
49+
toastDisplayed = true;
50+
toastNotifications.addWarning(warningMsg);
51+
}
52+
console.warn(warningMsg);
53+
return {
54+
maxResultWindow: DEFAULT_MAX_RESULT_WINDOW,
55+
maxInnerResultWindow: DEFAULT_MAX_INNER_RESULT_WINDOW,
56+
};
57+
}
58+
}

x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import { indexPatternService } from '../../../kibana_services';
2222
import { i18n } from '@kbn/i18n';
2323
import { getTermsFields, getSourceFields } from '../../../index_pattern_util';
2424
import { ValidatedRange } from '../../../components/validated_range';
25-
import { SORT_ORDER } from '../../../../common/constants';
25+
import { DEFAULT_MAX_INNER_RESULT_WINDOW, SORT_ORDER } from '../../../../common/constants';
2626
import { ESDocField } from '../../fields/es_doc_field';
2727
import { FormattedMessage } from '@kbn/i18n/react';
28+
import { loadIndexSettings } from './load_index_settings';
2829

2930
export class UpdateSourceEditor extends Component {
3031
static propTypes = {
@@ -43,17 +44,31 @@ export class UpdateSourceEditor extends Component {
4344
sourceFields: null,
4445
termFields: null,
4546
sortFields: null,
47+
maxInnerResultWindow: DEFAULT_MAX_INNER_RESULT_WINDOW,
4648
};
4749

4850
componentDidMount() {
4951
this._isMounted = true;
5052
this.loadFields();
53+
this.loadIndexSettings();
5154
}
5255

5356
componentWillUnmount() {
5457
this._isMounted = false;
5558
}
5659

60+
async loadIndexSettings() {
61+
try {
62+
const indexPattern = await indexPatternService.get(this.props.indexPatternId);
63+
const { maxInnerResultWindow } = await loadIndexSettings(indexPattern.title);
64+
if (this._isMounted) {
65+
this.setState({ maxInnerResultWindow });
66+
}
67+
} catch (err) {
68+
return;
69+
}
70+
}
71+
5772
async loadFields() {
5873
let indexPattern;
5974
try {
@@ -149,7 +164,7 @@ export class UpdateSourceEditor extends Component {
149164
>
150165
<ValidatedRange
151166
min={1}
152-
max={100}
167+
max={this.state.maxInnerResultWindow}
153168
step={1}
154169
value={this.props.topHitsSize}
155170
onChange={this.onTopHitsSizeChange}

x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
jest.mock('../../../kibana_services', () => ({}));
88

9+
jest.mock('./load_index_settings', () => ({
10+
loadIndexSettings: async () => {
11+
return { maxInnerResultWindow: 100 };
12+
},
13+
}));
14+
915
import React from 'react';
1016
import { shallow } from 'enzyme';
1117

x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import _ from 'lodash';
99
import { Schemas } from 'ui/vis/editors/default/schemas';
1010
import { AggConfigs } from 'ui/agg_types';
1111
import { i18n } from '@kbn/i18n';
12-
import { ES_SIZE_LIMIT, FIELD_ORIGIN, METRIC_TYPE } from '../../../common/constants';
12+
import { DEFAULT_MAX_BUCKETS_LIMIT, FIELD_ORIGIN, METRIC_TYPE } from '../../../common/constants';
1313
import { ESDocField } from '../fields/es_doc_field';
1414
import { AbstractESAggSource } from './es_agg_source';
1515

@@ -170,7 +170,7 @@ export class ESTermSource extends AbstractESAggSource {
170170
schema: 'segment',
171171
params: {
172172
field: this._termField.getName(),
173-
size: ES_SIZE_LIMIT,
173+
size: DEFAULT_MAX_BUCKETS_LIMIT,
174174
},
175175
},
176176
];

0 commit comments

Comments
 (0)