From 7d4495f2e2bc994909ae80e543d3a3e0476f9ae0 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Mon, 1 Mar 2021 17:35:50 -0700 Subject: [PATCH] Update geo shape filter queries to use bounding box logic --- .../elasticsearch_geo_utils.d.ts | 3 +-- .../elasticsearch_geo_utils.js | 27 ++++--------------- .../classes/sources/es_source/es_source.ts | 6 +---- 3 files changed, 7 insertions(+), 29 deletions(-) diff --git a/x-pack/plugins/maps/common/elasticsearch_util/elasticsearch_geo_utils.d.ts b/x-pack/plugins/maps/common/elasticsearch_util/elasticsearch_geo_utils.d.ts index d7d76ab8acd37..2a3741146d454 100644 --- a/x-pack/plugins/maps/common/elasticsearch_util/elasticsearch_geo_utils.d.ts +++ b/x-pack/plugins/maps/common/elasticsearch_util/elasticsearch_geo_utils.d.ts @@ -47,8 +47,7 @@ export interface ESPolygonFilter { export function createExtentFilter( mapExtent: MapExtent, - geoFieldName: string, - geoFieldType: ES_GEO_FIELD_TYPE + geoFieldName: string ): ESPolygonFilter | ESGeoBoundingBoxFilter; export function makeESBbox({ maxLat, maxLon, minLat, minLon }: MapExtent): ESBBox; diff --git a/x-pack/plugins/maps/common/elasticsearch_util/elasticsearch_geo_utils.js b/x-pack/plugins/maps/common/elasticsearch_util/elasticsearch_geo_utils.js index c6b1c712925f0..cb80fa4401810 100644 --- a/x-pack/plugins/maps/common/elasticsearch_util/elasticsearch_geo_utils.js +++ b/x-pack/plugins/maps/common/elasticsearch_util/elasticsearch_geo_utils.js @@ -280,33 +280,16 @@ export function makeESBbox({ maxLat, maxLon, minLat, minLon }) { return esBbox; } -function createGeoBoundBoxFilter({ maxLat, maxLon, minLat, minLon }, geoFieldName) { - const boundingBox = makeESBbox({ maxLat, maxLon, minLat, minLon }); - return { - geo_bounding_box: { - [geoFieldName]: boundingBox, - }, - }; -} - -export function createExtentFilter(mapExtent, geoFieldName, geoFieldType) { - ensureGeoField(geoFieldType); - +export function createExtentFilter(mapExtent, geoFieldName) { // Extent filters are used to dynamically filter data for the current map view port. // Continue to use geo_bounding_box queries for extent filters // 1) geo_bounding_box queries are faster than polygon queries // 2) geo_shape benefits of pre-indexed shapes and - // compatability across multi-indices with geo_point and geo_shape do not apply to this use case. - if (geoFieldType === ES_GEO_FIELD_TYPE.GEO_POINT) { - return createGeoBoundBoxFilter(mapExtent, geoFieldName); - } - + // compatibility across multi-indices with geo_point and geo_shape do not apply to this use case. + const boundingBox = makeESBbox(mapExtent); return { - geo_shape: { - [geoFieldName]: { - shape: formatEnvelopeAsPolygon(mapExtent), - relation: ES_SPATIAL_RELATIONS.INTERSECTS, - }, + geo_bounding_box: { + [geoFieldName]: boundingBox, }, }; } diff --git a/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts b/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts index f6f0a234bcd67..945369829cfdf 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts @@ -236,11 +236,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource typeof searchFilters.geogridPrecision === 'number' ? expandToTileBoundaries(searchFilters.buffer, searchFilters.geogridPrecision) : searchFilters.buffer; - const extentFilter = createExtentFilter( - buffer, - geoField.name, - geoField.type as ES_GEO_FIELD_TYPE - ); + const extentFilter = createExtentFilter(buffer, geoField.name); // @ts-expect-error allFilters.push(extentFilter);