-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add website documentation for queries (#223)
- Loading branch information
Showing
26 changed files
with
465 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
id: elastic_query_bool | ||
title: "Boolean Query" | ||
--- | ||
|
||
The query that matches documents matching boolean combinations of other queries. It is built using one or more boolean clauses (queries): | ||
- `filter`: The clause (query) must appear in matching documents. However, unlike `must` the score of the query will be ignored. | ||
- `must`: the clause (query) must appear in matching documents and will contribute to the score. | ||
- `must not`: the clause (query) must not appear in the matching documents. | ||
- `should`: the clause (query) should appear in the matching document. | ||
|
||
In order to use the `Bool` query import the following: | ||
```scala | ||
import zio.elasticsearch.query.BoolQuery | ||
import zio.elasticsearch.ElasticQuery._ | ||
``` | ||
|
||
The `Bool` query can be created with `filter`, `must`, `mustNot` or `should` method: | ||
```scala | ||
val filterQuery: BoolQuery = filter(contains(field = Document.name, value = "a"), startsWith(field = Document.id, value = "b")) | ||
val mustQuery: BoolQuery = must(contains(field = Document.name, value = "a"), startsWith(field = Document.id, value = "b")) | ||
val mustNotQuery: BoolQuery = mustNot(contains(field = Document.name, value = "a")) | ||
val shouldQuery: BoolQuery = should(startsWith(field = Document.name, value = "a")) | ||
``` | ||
|
||
Once the `Bool` query is created, you can call `filter`, `must`, `mustNot`, `should`, `boost` and `minimumShouldMatch` methods on it. | ||
|
||
If you want to add `Filter` query to `Bool` query, you can use `filter` method (you can also call `filter` method on `Bool` query that is created with `filter` method): | ||
```scala | ||
val filterQuery: BoolQuery = filter(contains(field = Document.name, value = "a")).filter(contains(field = Document.name, value = "c")) | ||
``` | ||
|
||
If you want to add `Must` query to the `Bool` query, you can use `must` method: | ||
```scala | ||
val boolQuery: BoolQuery = filter(contains(field = Document.name, value = "a")).must(contains(field = Document.name, value = "c")) | ||
``` | ||
|
||
If you want to add `MustNot` query to the `Bool` query, you can use `mustNot` method: | ||
```scala | ||
val boolQuery: BoolQuery = filter(contains(field = Document.name, value = "a")).mustNot(contains(field = Document.name, value = "c")) | ||
``` | ||
|
||
If you want to add `Should` query to the `Bool` query, you can use `should` method: | ||
```scala | ||
val boolQuery: BoolQuery = filter(contains(field = Document.name, value = "a")).should(contains(field = Document.name, value = "c")) | ||
``` | ||
|
||
If you want to change the `_score` parameter, you can use the `boost` method: | ||
```scala | ||
val queryWithBoost: BoolQuery = filter(contains(field = Document.name, value = "a")).boost(1.2) | ||
``` | ||
|
||
If you want to change the `minimum_should_match` parameter, you can use the `minimumShouldMatch` method: | ||
```scala | ||
val queryWithMinimumShouldMatch: BoolQuery = should(contains(field = Document.name, value = "a")).minimumShouldMatch(2) | ||
``` | ||
|
||
You can find more information about Boolean Query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-bool-query.html). |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
id: elastic_query_geo_distance | ||
title: "Geo-distance Query" | ||
--- | ||
|
||
The `GeoDistance` query matches [geo_point](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/geo-point.html) and [geo_shape](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/geo-shape.html) values within a given distance of a geopoint. | ||
|
||
In order to use the `GeoDistance` query import the following: | ||
```scala | ||
import zio.elasticsearch.query.GeoDistanceQuery | ||
import zio.elasticsearch.ElasticQuery._ | ||
``` | ||
|
||
You can create a `GeoDistance` query using the `geoDistance` method with latitude and longitude in the following manner: | ||
```scala | ||
val query: GeoDistanceQuery = geoDistance(field = "location", latitude = 20.0, longitude = 20.0) | ||
``` | ||
|
||
You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `GeoDistance` query using the `geoDistance` method with latitude and longitude in the following manner: | ||
```scala | ||
val query: GeoDistanceQuery = geoDistance(field = Document.location, latitude = 20.0, longitude = 20.0) | ||
``` | ||
|
||
You can create a `GeoDistance` query using the `geoDistance` method with coordinates in the following manner: | ||
```scala | ||
val query: GeoDistanceQuery = geoDistance(field = "location", coordinates = "40,31") | ||
``` | ||
|
||
You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `GeoDistance` query using the `geoDistance` method with coordinates in the following manner: | ||
```scala | ||
val query: GeoDistanceQuery = geoDistance(field = Document.location, coordinates = "40,31") | ||
``` | ||
|
||
If you want to change the `distance`, you can use `distance` method: | ||
```scala | ||
import zio.elasticsearch.query.DistanceUnit | ||
|
||
val queryWithDistance: GeoDistanceQuery = geoDistance(field = "location", coordinates = "40,31").distance(value = 20.0, unit = DistanceUnit.Kilometers) | ||
``` | ||
|
||
If you want to change the `distance_type`, you can use `distanceType` method: | ||
```scala | ||
import zio.elasticsearch.query.DistanceType | ||
|
||
val queryWithDistanceType: GeoDistanceQuery = geoDistance(field = "location", coordinates = "40,31").distanceType(value = DistanceType.Plane) | ||
``` | ||
|
||
If you want to change the `_name`, you can use `name` method: | ||
```scala | ||
val queryWithName: GeoDistanceQuery = geoDistance(field = "location", coordinates = "40,31").name("name") | ||
``` | ||
|
||
If you want to change the `validation_method`, you can use `validationMethod` method: | ||
```scala | ||
import zio.elasticsearch.query.ValidationMethod | ||
|
||
val queryWithValidationMethod: GeoDistanceQuery = geoDistance(field = "location", coordinates = "40,31").validationMethod(value = ValidationMethod.IgnoreMalformed) | ||
``` | ||
|
||
You can find more information about `GeoDistance` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-geo-distance-query.html#query-dsl-geo-distance-query). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
id: elastic_query_match | ||
title: "Match Query" | ||
--- | ||
|
||
The `Match` query is a type of query that searches for a provided text, number, date or boolean value. | ||
This is the standard query for performing a full-text search, including options for fuzzy matching. | ||
|
||
In order to use the `Match` query import the following: | ||
|
||
```scala | ||
import zio.elasticsearch.query.MatchQuery | ||
import zio.elasticsearch.ElasticQuery._ | ||
``` | ||
|
||
You can create a `Match` query using the `matches` method in the following manner: | ||
```scala | ||
val query: MatchQuery = matches(field = "message", value = "this is a test") | ||
``` | ||
|
||
You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Match` query using the `matches` method in the following manner: | ||
```scala | ||
val query: MatchQuery = matches(field = Document.message, value = "this is a test") | ||
``` | ||
|
||
You can find more information about `Match` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html#query-dsl-match-query). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.