Skip to content

Commit

Permalink
Support of GeoJson Point for GeoPoint field (#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]>
(cherry picked from commit a282d39)
  • Loading branch information
heemin32 committed Oct 19, 2022
1 parent a44370d commit 1a1d1c5
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 @@ -17,6 +17,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Support for labels on version bump PRs, skip label support for changelog verifier ([#4391](https://github.com/opensearch-project/OpenSearch/pull/4391))
- Add a new node role 'search' which is dedicated to provide search capability ([#4689](https://github.com/opensearch-project/OpenSearch/pull/4689))
- Introduce experimental searchable snapshot API ([#4680](https://github.com/opensearch-project/OpenSearch/pull/4680))
- 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
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 1a1d1c5

Please sign in to comment.