Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonaNedeljkovic committed Dec 14, 2023
1 parent c20d077 commit 39bc4ca
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
37 changes: 37 additions & 0 deletions docs/overview/queries/elastic_query_geo_polygon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
id: elastic_query_geo_polygon
title: "Geo-polygon Query"
---

A query returning hits that only fall within a polygon of points.

In order to use the `GeoPolygon` query import the following:
```scala
import zio.elasticsearch.query.GeoPolygonQuery
import zio.elasticsearch.ElasticQuery._
```

You can create a `GeoPolygon` query using the `geoPolygon` method with list of coordinates in the following manner:
```scala
val query: GeoPolygonQuery = geoPolygon(field = "location", List("0, 0", "0, 90", "90, 90", "90, 0"))
```

You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `GeoPolygon` query using the `geoPolygon` method with list of coordinates in the following manner:
```scala
val query: GeoPolygonQuery = geoPolygon(field = Document.location, List("0, 0", "0, 90", "90, 90", "90, 0"))
```


If you want to change the `_name`, you can use `name` method:
```scala
val queryWithName: GeoPolygonQuery = geoPolygon(field = "location", coordinates = List("0, 0", "0, 90", "90, 90", "90, 0")).name("name")
```

If you want to change the `validation_method`, you can use `validationMethod` method:
```scala
import zio.elasticsearch.query.ValidationMethod

val queryWithValidationMethod: GeoPolygonQuery = geoPolygon(field = "location", coordinates = List("0, 0", "0, 90", "90, 90", "90, 0")).validationMethod(value = ValidationMethod.IgnoreMalformed)
```

You can find more information about `GeoPolygon` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html).
Original file line number Diff line number Diff line change
Expand Up @@ -2688,7 +2688,7 @@ object HttpExecutorSpec extends IntegrationSpec {
|{
| "mappings": {
| "properties": {
| "locationField": {
| "geoPointField": {
| "type": "geo_point"
| }
| }
Expand All @@ -2702,16 +2702,17 @@ object HttpExecutorSpec extends IntegrationSpec {
_ <- Executor.execute(
ElasticRequest.create[TestDocument](geoPolygonIndex, document).refreshTrue
)

r1 <- Executor
.execute(
ElasticRequest.search(
geoPolygonIndex,
ElasticQuery
.geoPolygon("locationField", List("0, 0", "0, 90", "90, 90", "90, 0"))
.geoPolygon("geoPointField", List("0, 0", "0, 90", "90, 90", "90, 0"))
)
)
.documentAs[TestDocument]
} yield assertTrue(r1 == Chunk(document))
} yield assert(r1)(equalTo(Chunk(document)))
}
} @@ after(Executor.execute(ElasticRequest.deleteIndex(geoPolygonIndex)).orDie)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2983,9 +2983,10 @@ object ElasticQuerySpec extends ZIOSpecDefault {
geoPolygon(TestDocument.stringField, List("40, -70", "30, -80", "20, -90")).validationMethod(
IgnoreMalformed
)
val queryWithAllParams = geoPolygon(TestDocument.stringField, List("40, -70", "30, -80", "20, -90"))
.validationMethod(IgnoreMalformed)
.name("name")
val queryWithAllParams =
geoPolygon(TestDocument.stringField, List("40, -70", "30, -80", "20, -90"))
.validationMethod(IgnoreMalformed)
.name("name")

val expected =
"""
Expand Down
1 change: 1 addition & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
'overview/queries/elastic_query_function_score',
'overview/queries/elastic_query_fuzzy',
'overview/queries/elastic_query_geo_distance',
'overview/queries/elastic_query_geo_polygon',
'overview/queries/elastic_query_has_child',
'overview/queries/elastic_query_has_parent',
'overview/queries/elastic_query_match',
Expand Down

0 comments on commit 39bc4ca

Please sign in to comment.