Skip to content

Commit

Permalink
Add geo shape filter field
Browse files Browse the repository at this point in the history
Add new filter query, 'geo_shape' to search geospatial
field types .

Signed-off-by: Vijayan Balasubramanian <balasvij@amazon.com>
  • Loading branch information
VijayanB committed Mar 14, 2023
1 parent 1e127b0 commit aa02477
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Multiple DataSource] Refactor test connection to support SigV4 auth type ([#3456](https://github.com/opensearch-project/OpenSearch-Dashboards/issues/3456))
- [Darwin] Add support for Darwin for running OpenSearch snapshots with `yarn opensearch snapshot` ([#3537](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3537))
- [Vis Builder] Add metric to metric, bucket to bucket aggregation persistence ([#3495](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3495))
- [Data] Add geo shape filter field ([#3605](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3605))

### 🐛 Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { getGeoShapeFilterField } from './geo_shape_filter';

describe('geo shape filter', function () {
describe('getGeoShapeFilterField', function () {
it('should return the name of the field a geo_shape query is targeting', () => {
const filter = {
geo_shape: {
geoPointField: {
shape: {
coordinates: [{ lat: 1, lon: 1 }],
type: 'Polygon',
},
relation: 'intersects',
},
ignore_unmapped: true,
},
meta: {
disabled: false,
negate: false,
alias: null,
params: {
points: [{ lat: 1, lon: 1 }],
},
},
};
const result = getGeoShapeFilterField(filter);
expect(result).toBe('geoPointField');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { Filter, FilterMeta, LatLon } from './meta_filter';

export type SpatialRelations = 'intersects' | 'disjoint' | 'within' | 'contains';

export interface ShapeFilter {
type: string;
coordinates: LatLon[];
}

export interface PreIndexedShapeFilter {
index: string;
id: string;
path: string;
routing: string;
}

export type GeoShapeFilterMeta = FilterMeta & {
params: {
shape?: ShapeFilter;
indexed_shape?: PreIndexedShapeFilter;
relation?: SpatialRelations;
};
};

export type GeoShapeFilter = Filter & {
meta: GeoShapeFilterMeta;
geo_shape: any;
};

export const isGeoShapeFilter = (filter: any): filter is GeoShapeFilter =>
filter && filter.geo_shape;

export const getGeoShapeFilterField = (filter: GeoShapeFilter) => {
return filter.geo_shape && Object.keys(filter.geo_shape).find((key) => key !== 'ignore_unmapped');
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { getPhraseFilterField, isPhraseFilter } from './phrase_filter';
import { getPhrasesFilterField, isPhrasesFilter } from './phrases_filter';
import { getRangeFilterField, isRangeFilter } from './range_filter';
import { getMissingFilterField, isMissingFilter } from './missing_filter';
import { getGeoShapeFilterField, isGeoShapeFilter } from './geo_shape_filter';

export const getFilterField = (filter: Filter) => {
if (isExistsFilter(filter)) {
Expand All @@ -59,6 +60,9 @@ export const getFilterField = (filter: Filter) => {
if (isMissingFilter(filter)) {
return getMissingFilterField(filter);
}
if (isGeoShapeFilter(filter)) {
return getGeoShapeFilterField(filter);
}

return;
};

0 comments on commit aa02477

Please sign in to comment.