Skip to content

Commit

Permalink
[Backport 2.x]Support of GeoJson Point for GeoPoint field (#4597) (#4842
Browse files Browse the repository at this point in the history
)

* Support of GeoJson Point for GeoPoint field (#4597)

* Support of GeoJson Point for GeoPoint field

See opensearch-project/geospatial#152

Signed-off-by: Heemin Kim <[email protected]>
(cherry picked from commit a282d39)

* Run geojson yaml test for 2.4 and above only

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

Signed-off-by: Heemin Kim <[email protected]>
  • Loading branch information
heemin32 authored Oct 21, 2022
1 parent a273f27 commit 0503897
Show file tree
Hide file tree
Showing 8 changed files with 530 additions and 132 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Introduce experimental searchable snapshot API ([#4680](https://github.com/opensearch-project/OpenSearch/pull/4680))
- Introduce Remote translog feature flag([#4158](https://github.com/opensearch-project/OpenSearch/pull/4158))
- Add groupId value propagation tests for ZIP publication task ([#4848](https://github.com/opensearch-project/OpenSearch/pull/4848))
- Add support for GeoJson Point type in GeoPoint field ([#4597](https://github.com/opensearch-project/OpenSearch/pull/4597))

### Dependencies
- Bumps `com.diffplug.spotless` from 6.9.1 to 6.10.0
- Bumps `xmlbeans` from 5.1.0 to 5.1.1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
setup:
- do:
indices.create:
index: test_1
body:
settings:
number_of_replicas: 0
mappings:
properties:
location:
type: geo_point

---
"Single point test":
- skip:
version: " - 2.3.99"
reason: "geojson format is supported in 2.4 and above"
- 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":
- skip:
version: " - 2.3.99"
reason: "geojson format is supported in 2.4 and above"
- 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 0503897

Please sign in to comment.