Skip to content

Commit

Permalink
Support of GeoJson Point for GeoPoint field (opensearch-project#4597)
Browse files Browse the repository at this point in the history
* Support of GeoJson Point for GeoPoint field

See opensearch-project/geospatial#152

Signed-off-by: Heemin Kim <[email protected]>

* Refactored code based on comments

Signed-off-by: Heemin Kim <[email protected]>

* Add unit tests for GeoJson support

Signed-off-by: Heemin Kim <[email protected]>

* Resolve comments

* Remove negation expression
* Ignore case for GeoJson Point type to be consistent with geo_shape parsing

Signed-off-by: Heemin Kim <[email protected]>

* Added yaml test for geopoint

Signed-off-by: Heemin Kim <[email protected]>

Signed-off-by: Heemin Kim <[email protected]>
  • Loading branch information
heemin32 authored Oct 19, 2022
1 parent ec34737 commit a282d39
Show file tree
Hide file tree
Showing 8 changed files with 523 additions and 132 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added in-flight cancellation of SearchShardTask based on resource consumption ([#4565](https://github.com/opensearch-project/OpenSearch/pull/4565))
- Apply reproducible builds configuration for OpenSearch plugins through gradle plugin ([#4746](https://github.com/opensearch-project/OpenSearch/pull/4746))
- Add groupId value propagation tests for ZIP publication task ([#4772](https://github.com/opensearch-project/OpenSearch/pull/4772))
- Add support for GeoJson Point type in GeoPoint field ([#4597](https://github.com/opensearch-project/OpenSearch/pull/4597))

### Dependencies
- Bumps `log4j-core` from 2.18.0 to 2.19.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
setup:
- do:
indices.create:
index: test_1
body:
settings:
number_of_replicas: 0
mappings:
properties:
location:
type: geo_point

---
"Single point test":
- do:
bulk:
refresh: true
body:
- index:
_index: test_1
_id: 1
- location:
lon: 52.374081
lat: 4.912350
- index:
_index: test_1
_id: 2
- location: "4.901618,52.369219"
- index:
_index: test_1
_id: 3
- location: [ 52.371667, 4.914722 ]
- index:
_index: test_1
_id: 4
- location: "POINT (52.371667 4.914722)"
- index:
_index: test_1
_id: 5
- location: "t0v5zsq1gpzf"
- index:
_index: test_1
_id: 6
- location:
type: Point
coordinates: [ 52.371667, 4.914722 ]

- do:
search:
index: test_1
rest_total_hits_as_int: true
body:
query:
geo_shape:
location:
shape:
type: "envelope"
coordinates: [ [ 51, 5 ], [ 53, 3 ] ]

- match: { hits.total: 6 }

- do:
search:
index: test_1
rest_total_hits_as_int: true
body:
query:
geo_shape:
location:
shape:
type: "envelope"
coordinates: [ [ 151, 15 ], [ 153, 13 ] ]

- match: { hits.total: 0 }

---
"Multi points test":
- do:
bulk:
refresh: true
body:
- index:
_index: test_1
_id: 1
- location:
- {lon: 52.374081, lat: 4.912350}
- {lon: 152.374081, lat: 14.912350}
- index:
_index: test_1
_id: 2
- location:
- "4.901618,52.369219"
- "14.901618,152.369219"
- index:
_index: test_1
_id: 3
- location:
- [ 52.371667, 4.914722 ]
- [ 152.371667, 14.914722 ]
- index:
_index: test_1
_id: 4
- location:
- "POINT (52.371667 4.914722)"
- "POINT (152.371667 14.914722)"
- index:
_index: test_1
_id: 5
- location:
- "t0v5zsq1gpzf"
- "x6skg0zbhnum"
- index:
_index: test_1
_id: 6
- location:
- {type: Point, coordinates: [ 52.371667, 4.914722 ]}
- {type: Point, coordinates: [ 152.371667, 14.914722 ]}

- do:
search:
index: test_1
rest_total_hits_as_int: true
body:
query:
geo_shape:
location:
shape:
type: "envelope"
coordinates: [ [ 51, 5 ], [ 53, 3 ] ]

- match: { hits.total: 6 }

- do:
search:
index: test_1
rest_total_hits_as_int: true
body:
query:
geo_shape:
location:
shape:
type: "envelope"
coordinates: [ [ 151, 15 ], [ 153, 13 ] ]

- match: { hits.total: 6 }
6 changes: 5 additions & 1 deletion server/src/main/java/org/opensearch/common/geo/GeoPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ public GeoPoint resetFromString(String value, final boolean ignoreZValue, Effect
public GeoPoint resetFromCoordinates(String value, final boolean ignoreZValue) {
String[] vals = value.split(",");
if (vals.length > 3) {
throw new OpenSearchParseException("failed to parse [{}], expected 2 or 3 coordinates " + "but found: [{}]", vals.length);
throw new OpenSearchParseException(
"failed to parse [{}], expected 2 or 3 coordinates " + "but found: [{}]",
value,
vals.length
);
}
final double lat;
final double lon;
Expand Down
Loading

0 comments on commit a282d39

Please sign in to comment.