From 2491f28d931664fd78c7be02556c62c8f8bea38a Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Tue, 14 Jul 2020 18:17:20 -0600 Subject: [PATCH] [Maps] increase DEFAULT_MAX_BUCKETS_LIMIT to 65535 (#70313) (#71781) Co-authored-by: Elastic Machine Co-authored-by: Elastic Machine --- x-pack/plugins/maps/common/constants.ts | 2 +- .../maps/public/classes/fields/es_agg_field.ts | 6 ++++-- .../sources/es_geo_grid_source/es_geo_grid_source.js | 3 +++ .../plugins/maps/public/elasticsearch_geo_utils.js | 5 +++-- .../maps/public/elasticsearch_geo_utils.test.js | 12 ++++++------ 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/maps/common/constants.ts b/x-pack/plugins/maps/common/constants.ts index 98464427cc348..cf67ac4dd999f 100644 --- a/x-pack/plugins/maps/common/constants.ts +++ b/x-pack/plugins/maps/common/constants.ts @@ -90,7 +90,7 @@ export const DECIMAL_DEGREES_PRECISION = 5; // meters precision export const ZOOM_PRECISION = 2; export const DEFAULT_MAX_RESULT_WINDOW = 10000; export const DEFAULT_MAX_INNER_RESULT_WINDOW = 100; -export const DEFAULT_MAX_BUCKETS_LIMIT = 10000; +export const DEFAULT_MAX_BUCKETS_LIMIT = 65535; export const FEATURE_ID_PROPERTY_NAME = '__kbn__feature_id__'; export const FEATURE_VISIBLE_PROPERTY_NAME = '__kbn_isvisibleduetojoin__'; diff --git a/x-pack/plugins/maps/public/classes/fields/es_agg_field.ts b/x-pack/plugins/maps/public/classes/fields/es_agg_field.ts index e0f5c79f1d427..15779d22681c0 100644 --- a/x-pack/plugins/maps/public/classes/fields/es_agg_field.ts +++ b/x-pack/plugins/maps/public/classes/fields/es_agg_field.ts @@ -17,6 +17,8 @@ import { TopTermPercentageField } from './top_term_percentage_field'; import { ITooltipProperty, TooltipProperty } from '../tooltips/tooltip_property'; import { ESAggTooltipProperty } from '../tooltips/es_agg_tooltip_property'; +const TERMS_AGG_SHARD_SIZE = 5; + export interface IESAggField extends IField { getValueAggDsl(indexPattern: IndexPattern): unknown | null; getBucketCount(): number; @@ -100,7 +102,7 @@ export class ESAggField implements IESAggField { const field = getField(indexPattern, this.getRootName()); const aggType = this.getAggType(); - const aggBody = aggType === AGG_TYPE.TERMS ? { size: 1, shard_size: 1 } : {}; + const aggBody = aggType === AGG_TYPE.TERMS ? { size: 1, shard_size: TERMS_AGG_SHARD_SIZE } : {}; return { [aggType]: addFieldToDSL(aggBody, field), }; @@ -108,7 +110,7 @@ export class ESAggField implements IESAggField { getBucketCount(): number { // terms aggregation increases the overall number of buckets per split bucket - return this.getAggType() === AGG_TYPE.TERMS ? 1 : 0; + return this.getAggType() === AGG_TYPE.TERMS ? TERMS_AGG_SHARD_SIZE : 0; } supportsFieldMeta(): boolean { diff --git a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.js index 3902709eeb841..92f6c258af597 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.js @@ -161,6 +161,7 @@ export class ESGeoGridSource extends AbstractESAggSource { bounds: makeESBbox(bufferedExtent), field: this._descriptor.geoField, precision, + size: DEFAULT_MAX_BUCKETS_LIMIT, }, }, }, @@ -245,6 +246,8 @@ export class ESGeoGridSource extends AbstractESAggSource { bounds: makeESBbox(bufferedExtent), field: this._descriptor.geoField, precision, + size: DEFAULT_MAX_BUCKETS_LIMIT, + shard_size: DEFAULT_MAX_BUCKETS_LIMIT, }, aggs: { gridCentroid: { diff --git a/x-pack/plugins/maps/public/elasticsearch_geo_utils.js b/x-pack/plugins/maps/public/elasticsearch_geo_utils.js index efd243595db3e..0d247d389f478 100644 --- a/x-pack/plugins/maps/public/elasticsearch_geo_utils.js +++ b/x-pack/plugins/maps/public/elasticsearch_geo_utils.js @@ -400,8 +400,9 @@ export function getBoundingBoxGeometry(geometry) { export function formatEnvelopeAsPolygon({ maxLat, maxLon, minLat, minLon }) { // GeoJSON mandates that the outer polygon must be counterclockwise to avoid ambiguous polygons // when the shape crosses the dateline - const left = minLon; - const right = maxLon; + const lonDelta = maxLon - minLon; + const left = lonDelta > 360 ? -180 : minLon; + const right = lonDelta > 360 ? 180 : maxLon; const top = clampToLatBounds(maxLat); const bottom = clampToLatBounds(minLat); const topLeft = [left, top]; diff --git a/x-pack/plugins/maps/public/elasticsearch_geo_utils.test.js b/x-pack/plugins/maps/public/elasticsearch_geo_utils.test.js index a1e4e43f3ab75..adaeae66bee14 100644 --- a/x-pack/plugins/maps/public/elasticsearch_geo_utils.test.js +++ b/x-pack/plugins/maps/public/elasticsearch_geo_utils.test.js @@ -421,7 +421,7 @@ describe('createExtentFilter', () => { }); }); - it('should not clamp longitudes to -180 to 180', () => { + it('should clamp longitudes to -180 to 180 when lonitude wraps globe', () => { const mapExtent = { maxLat: 39, maxLon: 209, @@ -436,11 +436,11 @@ describe('createExtentFilter', () => { shape: { coordinates: [ [ - [-191, 39], - [-191, 35], - [209, 35], - [209, 39], - [-191, 39], + [-180, 39], + [-180, 35], + [180, 35], + [180, 39], + [-180, 39], ], ], type: 'Polygon',