From 9471368774eac7561fdf5f772a755fae39763218 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Mon, 3 Feb 2020 16:42:57 -0500 Subject: [PATCH 1/2] [Maps] set filter.meta.key to geoFieldName so query passes filterMatchesIndex --- .../filter_manager/lib/mappers/map_spatial_filter.test.ts | 7 +++++-- .../query/filter_manager/lib/mappers/map_spatial_filter.ts | 7 ++----- .../legacy/plugins/maps/public/elasticsearch_geo_utils.js | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.test.ts index fdd029c563cdd..70876b4e2be77 100644 --- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.test.ts @@ -24,6 +24,7 @@ describe('mapSpatialFilter()', () => { test('should return the key for matching multi polygon filter', async () => { const filter = { meta: { + key: 'location', alias: 'my spatial filter', type: esFilters.FILTERS.SPATIAL_FILTER, } as esFilters.FilterMeta, @@ -41,7 +42,7 @@ describe('mapSpatialFilter()', () => { } as esFilters.Filter; const result = mapSpatialFilter(filter); - expect(result).toHaveProperty('key', 'query'); + expect(result).toHaveProperty('key', 'location'); expect(result).toHaveProperty('value', ''); expect(result).toHaveProperty('type', esFilters.FILTERS.SPATIAL_FILTER); }); @@ -49,6 +50,7 @@ describe('mapSpatialFilter()', () => { test('should return the key for matching polygon filter', async () => { const filter = { meta: { + key: 'location', alias: 'my spatial filter', type: esFilters.FILTERS.SPATIAL_FILTER, } as esFilters.FilterMeta, @@ -58,7 +60,7 @@ describe('mapSpatialFilter()', () => { } as esFilters.Filter; const result = mapSpatialFilter(filter); - expect(result).toHaveProperty('key', 'geo_polygon'); + expect(result).toHaveProperty('key', 'location'); expect(result).toHaveProperty('value', ''); expect(result).toHaveProperty('type', esFilters.FILTERS.SPATIAL_FILTER); }); @@ -66,6 +68,7 @@ describe('mapSpatialFilter()', () => { test('should return undefined for none matching', async done => { const filter = { meta: { + key: 'location', alias: 'my spatial filter', } as esFilters.FilterMeta, geo_polygon: { diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts index 3cf1cf7835e69..8753a3efb50f3 100644 --- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts +++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts @@ -21,17 +21,14 @@ import { esFilters } from '../../../../../common'; // Use mapSpatialFilter mapper to avoid bloated meta with value and params for spatial filters. export const mapSpatialFilter = (filter: esFilters.Filter) => { const metaProperty = /(^\$|meta)/; - const key = Object.keys(filter).find(item => { - return !item.match(metaProperty); - }); if ( - key && filter.meta && + filter.meta.key && filter.meta.alias && filter.meta.type === esFilters.FILTERS.SPATIAL_FILTER ) { return { - key, + key: filter.meta.key, type: filter.meta.type, value: '', }; diff --git a/x-pack/legacy/plugins/maps/public/elasticsearch_geo_utils.js b/x-pack/legacy/plugins/maps/public/elasticsearch_geo_utils.js index 9aa5947062c83..ec0ae4161b3f2 100644 --- a/x-pack/legacy/plugins/maps/public/elasticsearch_geo_utils.js +++ b/x-pack/legacy/plugins/maps/public/elasticsearch_geo_utils.js @@ -297,6 +297,7 @@ function createGeometryFilterWithMeta({ type: SPATIAL_FILTER_TYPE, negate: false, index: indexPatternId, + key: geoFieldName, alias: `${geoFieldName} ${relationLabel} ${geometryLabel}`, }; From 0f7c670fbdb7df631fc34d12e945cdf755dcff7c Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Sun, 9 Feb 2020 11:00:12 -0700 Subject: [PATCH 2/2] remove unused variable --- .../query/filter_manager/lib/mappers/map_spatial_filter.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts index 8753a3efb50f3..ed2e5df82e37e 100644 --- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts +++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts @@ -20,7 +20,6 @@ import { esFilters } from '../../../../../common'; // Use mapSpatialFilter mapper to avoid bloated meta with value and params for spatial filters. export const mapSpatialFilter = (filter: esFilters.Filter) => { - const metaProperty = /(^\$|meta)/; if ( filter.meta && filter.meta.key &&