mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
* [7.5] [Maps] avoid duplicated geometry in filter meta (#51133) * fix type errors * more typescript fixes
This commit is contained in:
parent
ef74e2b289
commit
4533f66f33
8 changed files with 141 additions and 1 deletions
|
@ -84,4 +84,5 @@ export enum FILTERS {
|
|||
RANGE = 'range',
|
||||
GEO_BOUNDING_BOX = 'geo_bounding_box',
|
||||
GEO_POLYGON = 'geo_polygon',
|
||||
SPATIAL_FILTER = 'spatial_filter',
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
import { Filter } from '@kbn/es-query';
|
||||
import { reduceRight } from 'lodash';
|
||||
|
||||
import { mapSpatialFilter } from './map_spatial_filter';
|
||||
import { mapMatchAll } from './map_match_all';
|
||||
import { mapPhrase } from './map_phrase';
|
||||
import { mapPhrases } from './map_phrases';
|
||||
|
@ -50,6 +51,7 @@ export function mapFilter(filter: Filter) {
|
|||
// that either handles the mapping operation or not
|
||||
// and add it here. ProTip: These are executed in order listed
|
||||
const mappers = [
|
||||
mapSpatialFilter,
|
||||
mapMatchAll,
|
||||
mapRange,
|
||||
mapPhrase,
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { mapSpatialFilter } from './map_spatial_filter';
|
||||
import { Filter, FILTERS } from '@kbn/es-query';
|
||||
|
||||
describe('mapSpatialFilter()', () => {
|
||||
test('should return the key for matching multi polygon filter', async () => {
|
||||
const filter = {
|
||||
meta: {
|
||||
alias: 'my spatial filter',
|
||||
type: FILTERS.SPATIAL_FILTER,
|
||||
disabled: false,
|
||||
negate: false,
|
||||
},
|
||||
query: {
|
||||
bool: {
|
||||
should: [
|
||||
{
|
||||
geo_polygon: {
|
||||
geoCoordinates: { points: [] },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
} as Filter;
|
||||
const result = mapSpatialFilter(filter);
|
||||
|
||||
expect(result).toHaveProperty('key', 'query');
|
||||
expect(result).toHaveProperty('value', '');
|
||||
expect(result).toHaveProperty('type', FILTERS.SPATIAL_FILTER);
|
||||
});
|
||||
|
||||
test('should return the key for matching polygon filter', async () => {
|
||||
const filter = {
|
||||
meta: {
|
||||
alias: 'my spatial filter',
|
||||
type: FILTERS.SPATIAL_FILTER,
|
||||
disabled: false,
|
||||
negate: false,
|
||||
},
|
||||
geo_polygon: {
|
||||
geoCoordinates: { points: [] },
|
||||
},
|
||||
} as Filter;
|
||||
const result = mapSpatialFilter(filter);
|
||||
|
||||
expect(result).toHaveProperty('key', 'geo_polygon');
|
||||
expect(result).toHaveProperty('value', '');
|
||||
expect(result).toHaveProperty('type', FILTERS.SPATIAL_FILTER);
|
||||
});
|
||||
|
||||
test('should return undefined for none matching', async done => {
|
||||
const filter = {
|
||||
meta: {
|
||||
alias: 'my spatial filter',
|
||||
disabled: false,
|
||||
negate: false,
|
||||
},
|
||||
geo_polygon: {
|
||||
geoCoordinates: { points: [] },
|
||||
},
|
||||
} as Filter;
|
||||
|
||||
try {
|
||||
mapSpatialFilter(filter);
|
||||
} catch (e) {
|
||||
expect(e).toBe(filter);
|
||||
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { Filter, FILTERS } from '@kbn/es-query';
|
||||
|
||||
// Use mapSpatialFilter mapper to avoid bloated meta with value and params for spatial filters.
|
||||
export const mapSpatialFilter = (filter: Filter) => {
|
||||
const metaProperty = /(^\$|meta)/;
|
||||
const key = Object.keys(filter).find(item => {
|
||||
return !item.match(metaProperty);
|
||||
});
|
||||
if (key && filter.meta && filter.meta.alias && filter.meta.type === FILTERS.SPATIAL_FILTER) {
|
||||
return {
|
||||
key,
|
||||
type: filter.meta.type,
|
||||
value: '',
|
||||
};
|
||||
}
|
||||
throw filter;
|
||||
};
|
|
@ -14,6 +14,9 @@ import { GeometryFilterForm } from '../../../components/geometry_filter_form';
|
|||
import { UrlOverflowService } from 'ui/error_url_overflow';
|
||||
import rison from 'rison-node';
|
||||
|
||||
// over estimated and imprecise value to ensure filter has additional room for any meta keys added when filter is mapped.
|
||||
const META_OVERHEAD = 100;
|
||||
|
||||
const urlOverflow = new UrlOverflowService();
|
||||
|
||||
export class FeatureGeometryFilterForm extends Component {
|
||||
|
@ -70,7 +73,7 @@ export class FeatureGeometryFilterForm extends Component {
|
|||
|
||||
// Ensure filter will not overflow URL. Filters that contain geometry can be extremely large.
|
||||
// No elasticsearch support for pre-indexed shapes and geo_point spatial queries.
|
||||
if (window.location.href.length + rison.encode(filter).length > urlOverflow.failLength()) {
|
||||
if (window.location.href.length + rison.encode(filter).length + META_OVERHEAD > urlOverflow.failLength()) {
|
||||
this.setState({
|
||||
errorMsg: i18n.translate('xpack.maps.tooltip.geometryFilterForm.filterTooLargeMessage', {
|
||||
defaultMessage: 'Cannot create filter. Filters are added to the URL, and this shape has too many vertices to fit in the URL.'
|
||||
|
|
|
@ -18,6 +18,7 @@ import {
|
|||
LAT_INDEX,
|
||||
} from '../common/constants';
|
||||
import { getEsSpatialRelationLabel } from '../common/i18n_getters';
|
||||
import { SPATIAL_FILTER_TYPE } from './kibana_services';
|
||||
|
||||
function ensureGeoField(type) {
|
||||
const expectedTypes = [ES_GEO_FIELD_TYPE.GEO_POINT, ES_GEO_FIELD_TYPE.GEO_SHAPE];
|
||||
|
@ -287,6 +288,7 @@ function createGeometryFilterWithMeta({
|
|||
})
|
||||
: getEsSpatialRelationLabel(relation);
|
||||
const meta = {
|
||||
type: SPATIAL_FILTER_TYPE,
|
||||
negate: false,
|
||||
index: indexPatternId,
|
||||
alias: `${geoFieldName} ${relationLabel} ${geometryLabel}`
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
|
||||
jest.mock('ui/new_platform');
|
||||
jest.mock('ui/index_patterns');
|
||||
jest.mock('./kibana_services', () => {
|
||||
return {
|
||||
SPATIAL_FILTER_TYPE: 'spatial_filter'
|
||||
};
|
||||
});
|
||||
|
||||
import {
|
||||
hitsToGeoJson,
|
||||
|
|
|
@ -9,7 +9,9 @@ import { SearchSourceProvider } from 'ui/courier';
|
|||
import { getRequestInspectorStats, getResponseInspectorStats } from 'ui/courier/utils/courier_inspector_utils';
|
||||
export { xpackInfo } from 'plugins/xpack_main/services/xpack_info';
|
||||
import { start as data } from '../../../../../src/legacy/core_plugins/data/public/legacy';
|
||||
import { FILTERS } from '@kbn/es-query';
|
||||
|
||||
export const SPATIAL_FILTER_TYPE = FILTERS.SPATIAL_FILTER;
|
||||
export const indexPatternService = data.indexPatterns.indexPatterns;
|
||||
|
||||
export let SearchSource;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue