Geo queries
editGeo queries
editElasticsearch supports two types of geo data:
geo_point
fields which support lat/lon pairs, and
geo_shape
fields, which support points, lines, circles, polygons, multi-polygons etc.
The queries in this group are:
-
geo_shape
query - Find document with geo-shapes which either intersect, are contained by, or do not intersect with the specified geo-shape.
-
geo_bounding_box
query - Finds documents with geo-points that fall into the specified rectangle.
-
geo_distance
query - Finds document with geo-points within the specified distance of a central point.
-
geo_polygon
query - Find documents with geo-points within the specified polygon.
GeoShape Query
editSee Geo Shape Query
Note: the geo_shape
type uses Spatial4J
and JTS
, both of which are
optional dependencies. Consequently you must add Spatial4J
and JTS
to your classpath in order to use this type:
<dependency> <groupId>org.locationtech.spatial4j</groupId> <artifactId>spatial4j</artifactId> <version>0.7</version> </dependency> <dependency> <groupId>org.locationtech.jts</groupId> <artifactId>jts-core</artifactId> <version>1.15.0</version> <exclusions> <exclusion> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId> </exclusion> </exclusions> </dependency>
check for updates in Maven Central |
|
check for updates in Maven Central |
// Import ShapeRelation and ShapeBuilder import org.elasticsearch.common.geo.ShapeRelation; import org.elasticsearch.common.geo.builders.ShapeBuilder;
List<Point> points = new ArrayList<>(); points.add(new Point(0, 0)); points.add(new Point(0, 10)); points.add(new Point(10, 10)); points.add(new Point(10, 0)); points.add(new Point(0, 0)); GeoShapeQueryBuilder qb = geoShapeQuery( "pin.location", new MultiPoint(points) ); qb.relation(ShapeRelation.WITHIN);
field |
|
shape |
|
relation can be |