Skip to content

Commit

Permalink
[Maps] set filter.meta.key to geoFieldName so query passes filterMatc…
Browse files Browse the repository at this point in the history
…hesIndex when ignoreFilterIfFieldNotInIndex is true (elastic#56692)

* [Maps] set filter.meta.key to geoFieldName so query passes filterMatchesIndex

* remove unused variable

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
nreese and elasticmachine committed Feb 10, 2020
1 parent 7e034c4 commit 50ddb67
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -41,14 +42,15 @@ 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);
});

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,
Expand All @@ -58,14 +60,15 @@ 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);
});

test('should return undefined for none matching', async done => {
const filter = {
meta: {
key: 'location',
alias: 'my spatial filter',
} as esFilters.FilterMeta,
geo_polygon: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,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: '',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ function createGeometryFilterWithMeta({
type: SPATIAL_FILTER_TYPE,
negate: false,
index: indexPatternId,
key: geoFieldName,
alias: `${geoFieldName} ${relationLabel} ${geometryLabel}`,
};

Expand Down

0 comments on commit 50ddb67

Please sign in to comment.