Geo queriesedit
Elasticsearch 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_shapequery - Find document with geo-shapes which either intersect, are contained by, or do not intersect with the specified geo-shape.
-
geo_bounding_boxquery - Finds documents with geo-points that fall into the specified rectangle.
-
geo_distancequery - Finds document with geo-points within the specified distance of a central point.
-
geo_distance_rangequery -
Like the
geo_pointquery, but the range starts at a specified distance from the central point. -
geo_polygonquery - Find documents with geo-points within the specified polygon.
-
geohash_cellquery - Find geo-points whose geohash intersects with the geohash of the specified point.
GeoShape Queryedit
See 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>com.spatial4j</groupId>
<artifactId>spatial4j</artifactId>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>1.13</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;
QueryBuilder qb = geoShapeQuery(
"pin.location",
ShapeBuilder.newMultiPoint()
.point(0, 0)
.point(0, 10)
.point(10, 10)
.point(10, 0)
.point(0, 0),
ShapeRelation.WITHIN); 
field | |
shape | |
relation can be |
Geo Bounding Box Queryedit
Geo Distance Queryedit
QueryBuilder qb = geoDistanceQuery("pin.location")
.point(40, -70)
.distance(200, DistanceUnit.KILOMETERS)
.optimizeBbox("memory")
.geoDistance(GeoDistance.ARC); 
field | |
center point | |
distance from center point | |
optimize bounding box: | |
distance computation mode: |
Geo Distance Range Queryedit
QueryBuilder qb = geoDistanceRangeQuery("pin.location")
.point(40, -70)
.from("200km")
.to("400km")
.includeLower(true)
.includeUpper(false)
.optimizeBbox("memory")
.geoDistance(GeoDistance.ARC); 
field | |
center point | |
starting distance from center point | |
ending distance from center point | |
include lower value means that | |
include upper value means that | |
optimize bounding box: | |
distance computation mode: |