| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 | [[java-query-dsl-geo-shape-query]]==== GeoShape QuerySee {ref}/query-dsl-geo-shape-query.html[Geo Shape Query]Note: the `geo_shape` type uses `Spatial4J` and `JTS`, both of which areoptional dependencies. Consequently you must add `Spatial4J` and `JTS`to your classpath in order to use this type:[source,xml]-----------------------------------------------<dependency>    <groupId>org.locationtech.spatial4j</groupId>    <artifactId>spatial4j</artifactId>    <version>0.6</version>                        <1></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>-----------------------------------------------<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]<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]--------------------------------------------------// Import ShapeRelation and ShapeBuilderimport org.elasticsearch.common.geo.ShapeRelation;import org.elasticsearch.common.geo.builders.ShapeBuilder;--------------------------------------------------[source,java]--------------------------------------------------List<Coordinate> points = new ArrayList<>();points.add(new Coordinate(0, 0));points.add(new Coordinate(0, 10));points.add(new Coordinate(10, 10));points.add(new Coordinate(10, 0));points.add(new Coordinate(0, 0));QueryBuilder qb = geoShapeQuery(        "pin.location",                         <1>        ShapeBuilders.newMultiPoint(points)     <2>        .relation(ShapeRelation.WITHIN);        <3>--------------------------------------------------<1> field<2> shape<3> relation can be `ShapeRelation.CONTAINS`, `ShapeRelation.WITHIN`, `ShapeRelation.INTERSECTS` or `ShapeRelation.DISJOINT`[source,java]--------------------------------------------------// Using pre-indexed shapesQueryBuilder qb = geoShapeQuery(        "pin.location",                  <1>        "DEU",                           <2>        "countries")                     <3>        .relation(ShapeRelation.WITHIN)) <4>        .indexedShapeIndex("shapes")     <5>        .indexedShapePath("location");   <6>--------------------------------------------------<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'.
 |