-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new filter query, 'geo_shape' to search geospatial field types . Signed-off-by: Vijayan Balasubramanian <balasvij@amazon.com>
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/plugins/data/common/opensearch_query/filters/geo_shape_filter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
src/plugins/data/common/opensearch_query/filters/geo_shape_filter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters