diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js index 4a18fdc1a2e96..bfa4e27d00e05 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js @@ -175,7 +175,7 @@ export class ESGeoGridSource extends AbstractESAggSource { ); } - async getGeoJsonWithMeta(layerName, searchFilters, registerCancelCallback) { + async getGeoJsonWithMeta(layerName, searchFilters, prevMeta, registerCancelCallback) { const indexPattern = await this.getIndexPattern(); const searchSource = await this._makeSearchSource(searchFilters, 0); const aggConfigs = new AggConfigs( diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js index 66d62dd5644ac..72294b32ff27e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js @@ -174,7 +174,7 @@ export class ESPewPewSource extends AbstractESAggSource { return Math.min(targetGeotileLevel, MAX_GEOTILE_LEVEL); } - async getGeoJsonWithMeta(layerName, searchFilters, registerCancelCallback) { + async getGeoJsonWithMeta(layerName, searchFilters, prevMeta, registerCancelCallback) { const indexPattern = await this.getIndexPattern(); const metricAggConfigs = this.createMetricAggConfigs(); const aggConfigs = new AggConfigs(indexPattern, metricAggConfigs, aggSchemas.all); 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 470222a95eed9..926b272dbe3e1 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,6 +17,8 @@ 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, @@ -29,6 +31,23 @@ import { kfetch } from 'ui/kfetch'; 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', { @@ -299,20 +318,11 @@ export class ESSearchSource extends AbstractESSource { // searchFilters.fieldNames contains geo field and any fields needed for styling features // Performs Elasticsearch search request being careful to pull back only required fields to minimize response size - async _getSearchHits(layerName, searchFilters, registerCancelCallback) { + async _getSearchHits(layerName, searchFilters, maxResultWindow, registerCancelCallback) { const initialSearchContext = { docvalue_fields: await this._getDateDocvalueFields(searchFilters.fieldNames), }; const geoField = await this._getGeoField(); - const indexPattern = await this.getIndexPattern(); - - const indexSettings = await kfetch({ - pathname: `../${GIS_API_PATH}/indexSettings`, - query: { - indexPatternTitle: indexPattern.title, - }, - }); - console.log(indexSettings); let searchSource; if (geoField.type === ES_GEO_FIELD_TYPE.GEO_POINT) { @@ -324,7 +334,7 @@ export class ESSearchSource extends AbstractESSource { ); searchSource = await this._makeSearchSource( searchFilters, - 10000, + maxResultWindow, initialSearchContext ); searchSource.setField('source', false); // do not need anything from _source @@ -333,7 +343,7 @@ export class ESSearchSource extends AbstractESSource { // geo_shape fields do not support docvalue_fields yet, so still have to be pulled from _source searchSource = await this._makeSearchSource( searchFilters, - 10000, + maxResultWindow, initialSearchContext ); // Setting "fields" instead of "source: { includes: []}" @@ -374,12 +384,22 @@ export class ESSearchSource extends AbstractESSource { return !!sortField && !!sortOrder; } - async getGeoJsonWithMeta(layerName, searchFilters, registerCancelCallback) { + async getGeoJsonWithMeta(layerName, searchFilters, prevMeta, registerCancelCallback) { + const indexPattern = await this.getIndexPattern(); + + const indexSettings = prevMeta.indexSettings + ? prevMeta.indexSettings + : await loadIndexSettings(indexPattern.title); + const { hits, meta } = this._isTopHits() ? await this._getTopHits(layerName, searchFilters, registerCancelCallback) - : await this._getSearchHits(layerName, searchFilters, registerCancelCallback); + : await this._getSearchHits( + layerName, + searchFilters, + indexSettings.maxResultWindow, + registerCancelCallback + ); - const indexPattern = await this.getIndexPattern(); const unusedMetaFields = indexPattern.metaFields.filter(metaField => { return !['_id', '_index'].includes(metaField); }); @@ -408,7 +428,7 @@ export class ESSearchSource extends AbstractESSource { return { data: featureCollection, - meta, + meta: { ...meta, indexSettings }, }; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js index 8128e5ed233fa..6e8b2e1e7c6f5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js @@ -9,7 +9,7 @@ import _ from 'lodash'; import { Schemas } from 'ui/vis/editors/default/schemas'; import { AggConfigs } from 'ui/agg_types'; import { i18n } from '@kbn/i18n'; -import { DEFAULT_MAX_RESULT_WINDOW, FIELD_ORIGIN, METRIC_TYPE } from '../../../common/constants'; +import { DEFAULT_MAX_BUCKETS_LIMIT, FIELD_ORIGIN, METRIC_TYPE } from '../../../common/constants'; import { ESDocField } from '../fields/es_doc_field'; import { AbstractESAggSource } from './es_agg_source'; @@ -170,7 +170,7 @@ export class ESTermSource extends AbstractESAggSource { schema: 'segment', params: { field: this._termField.getName(), - size: DEFAULT_MAX_RESULT_WINDOW, + size: DEFAULT_MAX_BUCKETS_LIMIT, }, }, ]; diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index 30c47658bb327..72a756261d856 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -364,7 +364,6 @@ export class VectorLayer extends AbstractLayer { const requestToken = Symbol(`layer-${this.getId()}-${SOURCE_DATA_ID_ORIGIN}`); const searchFilters = this._getSearchFilters(dataFilters); const prevDataRequest = this.getSourceDataRequest(); - const canSkipFetch = await canSkipSourceUpdate({ source: this._source, prevDataRequest, @@ -383,6 +382,7 @@ export class VectorLayer extends AbstractLayer { const { data: sourceFeatureCollection, meta } = await this._source.getGeoJsonWithMeta( layerName, searchFilters, + prevDataRequest ? prevDataRequest.getMeta() : {}, registerCancelCallback.bind(null, requestToken) ); const layerFeatureCollection = assignFeatureIds(sourceFeatureCollection);