xy shape field type

An xy shape field type contains a shape, such as a polygon or a collection of xy points. It is based on the Lucene XYShape field type. To index an xy shape, OpenSearch tessellates the shape into a triangular mesh and stores each triangle in a BKD tree (a set of balanced k-dimensional trees). This provides a 10-7decimal degree of precision, which represents near-perfect spatial resolution.

The xy shape field type is similar to the geoshape field type, but it represents shapes on the Cartesian plane, which is not based on the Earth-fixed terrestrial reference system. The coordinates of an xy shape are single-precision floating-point values. For information about the range and precision of floating-point values, see Numeric field types.

Example

Create a mapping with an xy shape field type:

  1. PUT testindex
  2. {
  3. "mappings": {
  4. "properties": {
  5. "location": {
  6. "type": "xy_shape"
  7. }
  8. }
  9. }
  10. }

copy

Formats

xy shapes can be indexed in the following formats:

In both GeoJSON and WKT, the coordinates must be specified in the x, y order within coordinate arrays.

xy shape types

The following table describes the possible xy shape types and their relationship to the GeoJSON and WKT types.

OpenSearch typeGeoJSON typeWKT typeDescription
pointPointPOINTA geographic point specified by the x and y coordinates.
linestringLineStringLINESTRINGA line specified by two or more points. May be a straight line or a path of connected line segments.
polygonPolygonPOLYGONA polygon specified by a list of vertices in coordinate form. The polygon must be closed, meaning the last point must be the same as the first point. Therefore, to create an n-gon, n+1 vertices are required. The minimum number of vertices is four, which creates a triangle.
multipointMultiPointMULTIPOINTAn array of discrete related points that are not connected.
multilinestringMultiLineStringMULTILINESTRINGAn array of linestrings.
multipolygonMultiPolygonMULTIPOLYGONAn array of polygons.
geometrycollectionGeometryCollectionGEOMETRYCOLLECTIONA collection of xy shapes that may be of different types.
envelopeN/ABBOXA bounding rectangle specified by upper-left and lower-right vertices.

Point

A point is specified by a single pair of coordinates.

Index a point in GeoJSON format:

  1. PUT testindex/_doc/1
  2. {
  3. "location" : {
  4. "type" : "point",
  5. "coordinates" : [0.5, 4.5]
  6. }
  7. }

copy

Index a point in WKT format:

  1. PUT testindex/_doc/1
  2. {
  3. "location" : "POINT (0.5 4.5)"
  4. }

copy

Linestring

A linestring is a line specified by two or more points. If the points are collinear, the linestring is a straight line. Otherwise, the linestring represents a path made of line segments.

Index a linestring in GeoJSON format:

  1. PUT testindex/_doc/2
  2. {
  3. "location" : {
  4. "type" : "linestring",
  5. "coordinates" : [[0.5, 4.5], [-1.5, 2.3]]
  6. }
  7. }

copy

Index a linestring in WKT format:

  1. PUT testindex/_doc/2
  2. {
  3. "location" : "LINESTRING (0.5 4.5, -1.5 2.3)"
  4. }

copy

Polygon

A polygon is specified by a list of vertices in coordinate form. The polygon must be closed, meaning the last point must be the same as the first point. In the following example, a triangle is created using four points.

GeoJSON requires that you list the vertices of the polygon counterclockwise. WKT does not impose a specific order on vertices.

Index a polygon (triangle) in GeoJSON format:

  1. PUT testindex/_doc/3
  2. {
  3. "location" : {
  4. "type" : "polygon",
  5. "coordinates" : [
  6. [[0.5, 4.5],
  7. [2.5, 6.0],
  8. [1.5, 2.0],
  9. [0.5, 4.5]]
  10. ]
  11. }
  12. }

copy

Index a polygon (triangle) in WKT format:

  1. PUT testindex/_doc/3
  2. {
  3. "location" : "POLYGON ((0.5 4.5, 2.5 6.0, 1.5 2.0, 0.5 4.5))"
  4. }

copy

The polygon may have holes inside. In this case, the coordinates field will contain multiple arrays. The first array represents the outer polygon, and each subsequent array represents a hole. Holes are represented as polygons and specified as arrays of coordinates.

GeoJSON requires that you list the vertices of the polygon counterclockwise and the vertices of the hole clockwise. WKT does not impose a specific order on vertices.

Index a polygon (triangle) with a triangular hole in GeoJSON format:

  1. PUT testindex/_doc/4
  2. {
  3. "location" : {
  4. "type" : "polygon",
  5. "coordinates" : [
  6. [[0.5, 4.5],
  7. [2.5, 6.0],
  8. [1.5, 2.0],
  9. [0.5, 4.5]],
  10. [[1.0, 4.5],
  11. [1.5, 4.5],
  12. [1.5, 4.0],
  13. [1.0, 4.5]]
  14. ]
  15. }
  16. }

copy

Index a polygon (triangle) with a triangular hole in WKT format:

  1. PUT testindex/_doc/4
  2. {
  3. "location" : "POLYGON ((0.5 4.5, 2.5 6.0, 1.5 2.0, 0.5 4.5), (1.0 4.5, 1.5 4.5, 1.5 4.0, 1.0 4.5))"
  4. }

copy

By default, the vertices of the polygon are traversed in a counterclockwise order. You can define an orientation parameter to specify the vertex traversal order at mapping time:

  1. PUT testindex
  2. {
  3. "mappings": {
  4. "properties": {
  5. "location": {
  6. "type": "xy_shape",
  7. "orientation" : "left"
  8. }
  9. }
  10. }
  11. }

copy

Subsequently indexed documents can override the orientation setting:

  1. PUT testindex/_doc/3
  2. {
  3. "location" : {
  4. "type" : "polygon",
  5. "orientation" : "cw",
  6. "coordinates" : [
  7. [[0.5, 4.5],
  8. [2.5, 6.0],
  9. [1.5, 2.0],
  10. [0.5, 4.5]]
  11. ]
  12. }
  13. }

copy

Multipoint

A multipoint is an array of discrete related points that are not connected.

Index a multipoint in GeoJSON format:

  1. PUT testindex/_doc/6
  2. {
  3. "location" : {
  4. "type" : "multipoint",
  5. "coordinates" : [
  6. [0.5, 4.5],
  7. [2.5, 6.0]
  8. ]
  9. }
  10. }

copy

Index a multipoint in WKT format:

  1. PUT testindex/_doc/6
  2. {
  3. "location" : "MULTIPOINT (0.5 4.5, 2.5 6.0)"
  4. }

copy

Multilinestring

A multilinestring is an array of linestrings.

Index a multilinestring in GeoJSON format:

  1. PUT testindex/_doc/2
  2. {
  3. "location" : {
  4. "type" : "multilinestring",
  5. "coordinates" : [
  6. [[0.5, 4.5], [2.5, 6.0]],
  7. [[1.5, 2.0], [3.5, 3.5]]
  8. ]
  9. }
  10. }

copy

Index a linestring in WKT format:

  1. PUT testindex/_doc/2
  2. {
  3. "location" : "MULTILINESTRING ((0.5 4.5, 2.5 6.0), (1.5 2.0, 3.5 3.5))"
  4. }

copy

Multipolygon

A multipolygon is an array of polygons. In this example, the first polygon contains a hole, and the second does not.

Index a multipolygon in GeoJSON format:

  1. PUT testindex/_doc/4
  2. {
  3. "location" : {
  4. "type" : "multipolygon",
  5. "coordinates" : [
  6. [
  7. [[0.5, 4.5],
  8. [2.5, 6.0],
  9. [1.5, 2.0],
  10. [0.5, 4.5]],
  11. [[1.0, 4.5],
  12. [1.5, 4.5],
  13. [1.5, 4.0],
  14. [1.0, 4.5]]
  15. ],
  16. [
  17. [[2.0, 0.0],
  18. [1.0, 2.0],
  19. [3.0, 1.0],
  20. [2.0, 0.0]]
  21. ]
  22. ]
  23. }
  24. }

copy

Index a multipolygon in WKT format:

  1. PUT testindex/_doc/4
  2. {
  3. "location" : "MULTIPOLYGON (((0.5 4.5, 2.5 6.0, 1.5 2.0, 0.5 4.5), (1.0 4.5, 1.5 4.5, 1.5 4.0, 1.0 4.5)), ((2.0 0.0, 1.0 2.0, 3.0 1.0, 2.0 0.0)))"
  4. }

copy

Geometry collection

A geometry collection is a collection of xy shapes that may be of different types.

Index a geometry collection in GeoJSON format:

  1. PUT testindex/_doc/7
  2. {
  3. "location" : {
  4. "type": "geometrycollection",
  5. "geometries": [
  6. {
  7. "type": "point",
  8. "coordinates": [0.5, 4.5]
  9. },
  10. {
  11. "type": "linestring",
  12. "coordinates": [[2.5, 6.0], [1.5, 2.0]]
  13. }
  14. ]
  15. }
  16. }

copy

Index a geometry collection in WKT format:

  1. PUT testindex/_doc/7
  2. {
  3. "location" : "GEOMETRYCOLLECTION (POINT (0.5 4.5), LINESTRING(2.5 6.0, 1.5 2.0))"
  4. }

copy

Envelope

An envelope is a bounding rectangle specified by upper-left and lower-right vertices. The GeoJSON format is [[minX, maxY], [maxX, minY]].

Index an envelope in GeoJSON format:

  1. PUT testindex/_doc/2
  2. {
  3. "location" : {
  4. "type" : "envelope",
  5. "coordinates" : [[3.0, 2.0], [6.0, 0.0]]
  6. }
  7. }

copy

In WKT format, use BBOX (minX, maxY, maxX, minY).

Index an envelope in WKT BBOX format:

  1. PUT testindex/_doc/8
  2. {
  3. "location" : "BBOX (3.0, 2.0, 6.0, 0.0)"
  4. }

copy

Parameters

The following table lists the parameters accepted by xy shape field types. All parameters are optional.

ParameterDescription
coerceA Boolean value that specifies whether to automatically close unclosed linear rings. Default is false.
ignore_malformedA Boolean value that specifies to ignore malformed GeoJSON or WKT xy shapes and not to throw an exception. Default is false (throw an exception when xy shapes are malformed).
ignore_z_valueSpecific to points with three coordinates. If ignore_z_value is true, the third coordinate is not indexed but is still stored in the _source field. If ignore_z_value is false, an exception is thrown. Default is true.
orientationSpecifies the traversal order of the vertices in the xy shape’s list of coordinates. orientation takes the following values:
1. RIGHT: counterclockwise. Specify RIGHT orientation by using one of the following strings (uppercase or lowercase): right, counterclockwise, ccw.
2. LEFT: clockwise. Specify LEFT orientation by using one of the following strings (uppercase or lowercase): left, clockwise, cw. This value can be overridden by individual documents.
Default is RIGHT.