2015-06-24 17:27:19 -04:00
|
|
|
[[java-query-dsl-geo-shape-query]]
|
|
|
|
==== GeoShape Query
|
|
|
|
|
|
|
|
See {ref}/query-dsl-geo-shape-query.html[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:
|
|
|
|
|
|
|
|
[source,xml]
|
|
|
|
-----------------------------------------------
|
|
|
|
<dependency>
|
2016-03-07 04:12:23 -05:00
|
|
|
<groupId>org.locationtech.spatial4j</groupId>
|
2015-06-24 17:27:19 -04:00
|
|
|
<artifactId>spatial4j</artifactId>
|
2016-03-07 04:12:23 -05:00
|
|
|
<version>0.6</version> <1>
|
2015-06-24 17:27:19 -04:00
|
|
|
</dependency>
|
|
|
|
|
|
|
|
<dependency>
|
|
|
|
<groupId>com.vividsolutions</groupId>
|
|
|
|
<artifactId>jts</artifactId>
|
|
|
|
<version>1.13</version> <2>
|
|
|
|
<exclusions>
|
|
|
|
<exclusion>
|
|
|
|
<groupId>xerces</groupId>
|
|
|
|
<artifactId>xercesImpl</artifactId>
|
|
|
|
</exclusion>
|
|
|
|
</exclusions>
|
|
|
|
</dependency>
|
|
|
|
-----------------------------------------------
|
2016-03-07 04:12:23 -05:00
|
|
|
<1> check for updates in http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.locationtech.spatial4j%22%20AND%20a%3A%22spatial4j%22[Maven Central]
|
2015-06-24 17:27:19 -04:00
|
|
|
<2> check for updates in http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.vividsolutions%22%20AND%20a%3A%22jts%22[Maven Central]
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
2016-02-09 05:07:32 -05:00
|
|
|
// Import ShapeRelation and ShapeBuilder
|
2015-06-24 17:27:19 -04:00
|
|
|
import org.elasticsearch.common.geo.ShapeRelation;
|
|
|
|
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2017-05-02 13:00:56 -04:00
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
2015-06-24 17:27:19 -04:00
|
|
|
--------------------------------------------------
|
2017-05-02 13:00:56 -04:00
|
|
|
include-tagged::{query-dsl-test}[geo_shape]
|
2015-06-24 17:27:19 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> field
|
|
|
|
<2> shape
|
2016-11-28 11:33:40 -05:00
|
|
|
<3> relation can be `ShapeRelation.CONTAINS`, `ShapeRelation.WITHIN`, `ShapeRelation.INTERSECTS` or `ShapeRelation.DISJOINT`
|
2015-06-24 17:27:19 -04:00
|
|
|
|
2017-05-02 13:00:56 -04:00
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
2015-06-24 17:27:19 -04:00
|
|
|
--------------------------------------------------
|
2017-05-02 13:00:56 -04:00
|
|
|
include-tagged::{query-dsl-test}[indexed_geo_shape]
|
2015-06-24 17:27:19 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> field
|
|
|
|
<2> The ID of the document that containing the pre-indexed shape.
|
|
|
|
<3> Index type where the pre-indexed shape is.
|
|
|
|
<4> relation
|
|
|
|
<5> Name of the index where the pre-indexed shape is. Defaults to 'shapes'.
|
|
|
|
<6> The field specified as path containing the pre-indexed shape. Defaults to 'shape'.
|