geo-shape-query.asciidoc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. [[java-query-dsl-geo-shape-query]]
  2. ==== GeoShape Query
  3. See {ref}/query-dsl-geo-shape-query.html[Geo Shape Query]
  4. Note: the `geo_shape` type uses `Spatial4J` and `JTS`, both of which are
  5. optional dependencies. Consequently you must add `Spatial4J` and `JTS`
  6. to your classpath in order to use this type:
  7. [source,xml]
  8. -----------------------------------------------
  9. <dependency>
  10. <groupId>org.locationtech.spatial4j</groupId>
  11. <artifactId>spatial4j</artifactId>
  12. <version>0.7</version> <1>
  13. </dependency>
  14. <dependency>
  15. <groupId>org.locationtech.jts</groupId>
  16. <artifactId>jts-core</artifactId>
  17. <version>1.15.0</version> <2>
  18. <exclusions>
  19. <exclusion>
  20. <groupId>xerces</groupId>
  21. <artifactId>xercesImpl</artifactId>
  22. </exclusion>
  23. </exclusions>
  24. </dependency>
  25. -----------------------------------------------
  26. <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]
  27. <2> check for updates in http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.locationtech.jts%22%20AND%20a%3A%22jts-core%22[Maven Central]
  28. [source,java]
  29. --------------------------------------------------
  30. // Import ShapeRelation and ShapeBuilder
  31. import org.elasticsearch.common.geo.ShapeRelation;
  32. import org.elasticsearch.common.geo.builders.ShapeBuilder;
  33. --------------------------------------------------
  34. ["source","java",subs="attributes,callouts,macros"]
  35. --------------------------------------------------
  36. include-tagged::{query-dsl-test}[geo_shape]
  37. --------------------------------------------------
  38. <1> field
  39. <2> shape
  40. <3> relation can be `ShapeRelation.CONTAINS`, `ShapeRelation.WITHIN`, `ShapeRelation.INTERSECTS` or `ShapeRelation.DISJOINT`
  41. ["source","java",subs="attributes,callouts,macros"]
  42. --------------------------------------------------
  43. include-tagged::{query-dsl-test}[indexed_geo_shape]
  44. --------------------------------------------------
  45. <1> field
  46. <2> The ID of the document that containing the pre-indexed shape.
  47. <3> Index type where the pre-indexed shape is.
  48. <4> relation
  49. <5> Name of the index where the pre-indexed shape is. Defaults to 'shapes'.
  50. <6> The field specified as path containing the pre-indexed shape. Defaults to 'shape'.