diff --git a/docs/overview/queries/elastic_query_bool.md b/docs/overview/queries/elastic_query_bool.md new file mode 100644 index 000000000..8200ed14c --- /dev/null +++ b/docs/overview/queries/elastic_query_bool.md @@ -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). diff --git a/docs/overview/queries/elastic_query_contains.md b/docs/overview/queries/elastic_query_contains.md deleted file mode 100644 index 02901e557..000000000 --- a/docs/overview/queries/elastic_query_contains.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -id: elastic_query_contains -title: "Contains Query" ---- - -TBD diff --git a/docs/overview/queries/elastic_query_exists.md b/docs/overview/queries/elastic_query_exists.md index 6503b5c81..f75f21430 100644 --- a/docs/overview/queries/elastic_query_exists.md +++ b/docs/overview/queries/elastic_query_exists.md @@ -3,4 +3,22 @@ id: elastic_query_exists title: "Exists Query" --- -TBD +The `Exists` query is used for returning documents that contain an indexed value for a field. + +In order to use the `Exists` query import the following: +```scala +import zio.elasticsearch.query.ExistsQuery +import zio.elasticsearch.ElasticQuery._ +``` + +You can create an `Exists` query using the `exists` method this way: +```scala +val query: ExistsQuery = exists(field = "name") +``` + +Also, you can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Exists` query using the `exists` method this way: +```scala +val query: ExistsQuery = exists(field = Document.name) +``` + +You can find more information about Exists query [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html#query-dsl-exists-query). diff --git a/docs/overview/queries/elastic_query_filter.md b/docs/overview/queries/elastic_query_filter.md deleted file mode 100644 index 9f938e9b1..000000000 --- a/docs/overview/queries/elastic_query_filter.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -id: elastic_query_filter -title: "Filter Query" ---- - -TBD diff --git a/docs/overview/queries/elastic_query_geo_distance.md b/docs/overview/queries/elastic_query_geo_distance.md new file mode 100644 index 000000000..d554e554a --- /dev/null +++ b/docs/overview/queries/elastic_query_geo_distance.md @@ -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). diff --git a/docs/overview/queries/elastic_query_has_child.md b/docs/overview/queries/elastic_query_has_child.md index faeae1172..9b7fd44d8 100644 --- a/docs/overview/queries/elastic_query_has_child.md +++ b/docs/overview/queries/elastic_query_has_child.md @@ -3,4 +3,43 @@ id: elastic_query_has_child title: "Has Child Query" --- -TBD +The `HasChild` query returns parent documents whose child documents match a provided query. + +To create a `HasChild` query do the following: +```scala +import zio.elasticsearch.query.HasChildQuery +import zio.elasticsearch.ElasticQuery._ + +val query: HasChildQuery = hasChild(childType = "child", query = matches(Document.stringField, "test")) +``` + +If you want to change `ignore_unmapped`, you can use `ignoreUnmapped` method: +```scala +val queryWithIgnoreUnmapped: HasChildQuery = hasChild(childType = "child", query = matches(Document.stringField, "test")).ignoreUnmapped(true) +``` + +If you want to change `inner_hits`, you can use `innerHits` method: +```scala +import zio.elasticsearch.query.InnerHits + +val queryWithInnerHits: HasChildQuery = hasChild(childType = "child", query = matches(Document.stringField, "test")).innerHits(innerHits = InnerHits.from(5)) +``` + +If you want to change `max_children`, you can use `maxChildren` method: +```scala +val queryWithMaxChildren: HasChildQuery = hasChild(childType = "child", query = matches(Document.stringField, "test")).maxChildren(5) +``` + +If you want to change `min_children`, you can use `minChildren` method: +```scala +val queryWithMinChildren: HasChildQuery = hasChild(childType = "child", query = matches(Document.stringField, "test")).minChildren(2) +``` + +If you want to change `score_mode`, you can use `scoreMode` method: +```scala +import zio.elasticsearch.query.ScoreMode + +val queryWithScoreMode: HasChildQuery = hasChild(childType = "child", query = matches(Document.stringField, "test")).scoreMode(ScoreMode.Max) +``` + +You can find more information about `HasChild` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html). diff --git a/docs/overview/queries/elastic_query_has_parent.md b/docs/overview/queries/elastic_query_has_parent.md index 5cd7a69b6..4eadc5af3 100644 --- a/docs/overview/queries/elastic_query_has_parent.md +++ b/docs/overview/queries/elastic_query_has_parent.md @@ -3,4 +3,33 @@ id: elastic_query_has_parent title: "Has Parent Query" --- -TBD +The `HasParent` query returns child documents whose parent document matches a provided query. + +To create a `HasParent` query do the following: +```scala +import zio.elasticsearch.query.HasParentQuery +import zio.elasticsearch.ElasticQuery._ + +val query: HasParentQuery = hasParent(parentType = "parent", query = matches(Document.stringField, "test")) +``` + +If you want to change `ignore_unmapped`, you can use `ignoreUnmapped` method: +```scala +val queryWithIgnoreUnmapped: HasParentQuery = hasParent(parentType = "parent", query = matches(Document.stringField, "test")).ignoreUnmapped(true) +``` + +If you want to change `inner_hits`, you can use `innerHits` method: +```scala +import zio.elasticsearch.query.InnerHits + +val queryWithInnerHits: HasParentQuery = hasParent(parentType = "parent", query = matches(Document.stringField, "test")).innerHits(innerHits = InnerHits.from(5)) +``` + +If you want to change `score`, you can use `withScore`, `withScoreFalse` or `withScoreTrue` method: +```scala +val queryWithScore: HasParentQuery = hasParent(parentType = "parent", query = matches(Document.intField, "test")).withScore(true) +val queryWithScoreFalse: HasParentQuery = hasParent(parentType = "parent", query = matches(Document.intField, "test")).withScoreFalse +val queryWithScoreTrue: HasParentQuery = hasParent(parentType = "parent", query = matches(Document.intField, "test")).withScoreTrue +``` + +You can find more information about `HasParent` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-has-parent-query.html). diff --git a/docs/overview/queries/elastic_query_match.md b/docs/overview/queries/elastic_query_match.md new file mode 100644 index 000000000..6bf77c2e6 --- /dev/null +++ b/docs/overview/queries/elastic_query_match.md @@ -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). diff --git a/docs/overview/queries/elastic_query_match_all.md b/docs/overview/queries/elastic_query_match_all.md index 73bf368e2..3d9e4d0f1 100644 --- a/docs/overview/queries/elastic_query_match_all.md +++ b/docs/overview/queries/elastic_query_match_all.md @@ -3,10 +3,9 @@ id: elastic_query_match_all title: "Match All Query" --- -The most simple query, which matches all documents, giving them all a `_score` of `1.0`. +The most simple query, which matches all documents, giving them all a `score` of `1.0`. To create a `MatchAll` query do the following: - ```scala import zio.elasticsearch.query.MatchAllQuery import zio.elasticsearch.ElasticQuery._ @@ -14,8 +13,9 @@ import zio.elasticsearch.ElasticQuery._ val query: MatchAllQuery = matchAll ``` -If you want to change the `_score`, you can use the `boost` method: - +If you want to change the `boost`, you can use the `boost` method: ```scala val queryWithBoost: MatchAllQuery = matchAll.boost(1.2) ``` + +You can find more information about `MatchAll` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-match-all-query.html). diff --git a/docs/overview/queries/elastic_query_match_phrase.md b/docs/overview/queries/elastic_query_match_phrase.md index 1b0a161cc..baf597760 100644 --- a/docs/overview/queries/elastic_query_match_phrase.md +++ b/docs/overview/queries/elastic_query_match_phrase.md @@ -3,4 +3,22 @@ id: elastic_query_match_phrase title: "Match Phrase Query" --- -TBD +The `MatchPhrase` query analyzes the text and creates a `phrase` query out of the analyzed text. + +In order to use the `MatchPhrase` query import the following: +```scala +import zio.elasticsearch.query.MatchPhraseQuery +import zio.elasticsearch.ElasticQuery._ +``` + +You can create a `MatchPhrase` query using the `matchPhrase` method this way: +```scala +val query: MatchPhraseQuery = matchPhrase(field = "stringField", value = "test") +``` + +You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `MatchPhrase` query using the `matchPhrase` method this way: +```scala +val query: MatchPhraseQuery = matchPhrase(field = Document.stringField, value = "test") +``` + +You can find more information about `MatchPhrase` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-match-query-phrase.html). diff --git a/docs/overview/queries/elastic_query_matches.md b/docs/overview/queries/elastic_query_matches.md deleted file mode 100644 index e1e4631e9..000000000 --- a/docs/overview/queries/elastic_query_matches.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -id: elastic_query_matches -title: "Matches Query" ---- - -TBD diff --git a/docs/overview/queries/elastic_query_must.md b/docs/overview/queries/elastic_query_must.md deleted file mode 100644 index 4e0f87a31..000000000 --- a/docs/overview/queries/elastic_query_must.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -id: elastic_query_must -title: "Must Query" ---- - -TBD diff --git a/docs/overview/queries/elastic_query_must_not.md b/docs/overview/queries/elastic_query_must_not.md deleted file mode 100644 index e84feb09b..000000000 --- a/docs/overview/queries/elastic_query_must_not.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -id: elastic_query_must_not -title: "Must Not Query" ---- - -TBD diff --git a/docs/overview/queries/elastic_query_nested.md b/docs/overview/queries/elastic_query_nested.md index eec1e72db..5af5ef91c 100644 --- a/docs/overview/queries/elastic_query_nested.md +++ b/docs/overview/queries/elastic_query_nested.md @@ -3,4 +3,41 @@ id: elastic_query_nested title: "Nested Query" --- -TBD +The `Nested` query searches nested field objects as if they were indexed as separate documents. If an object matches the search, the Nested query returns the root parent document. + +In order to use the `Nested` query import the following: +```scala +import zio.elasticsearch.query.NestedQuery +import zio.elasticsearch.ElasticQuery._ +``` + +You can create a `Nested` query using the `nested` method in the following manner: +```scala +val query: NestedQuery = nested(path = "testField", query = matchAll) +``` + +You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Nested` query using the `nested` method in the following manner: +```scala +val query: NestedQuery = nested(path = Document.subDocumentList, query = matchAll) +``` + +If you want to change the `ignore_unmapped`, you can use `ignoreUnmapped` method: +```scala +val queryWithIgnoreUnmapped: NestedQuery = nested(path = Document.subDocumentList, query = matchAll).ignoreUnmapped(true) +``` + +If you want to change the `inner_hits`, you can use `innerHits` method: +```scala +import zio.elasticsearch.query.InnerHits + +val queryWithInnerHits: NestedQuery = nested(path = Document.subDocumentList, query = matchAll).innerHits(innerHits = InnerHits.from(5)) +``` + +If you want to change the `score_mode`, you can use `scoreMode` method: +```scala +import zio.elasticsearch.query.ScoreMode + +val queryWithScoreMode: NestedQuery = nested(path = Document.subDocumentList, query = matchAll).scoreMode(ScoreMode.Avg) +``` + +You can find more information about `Nested` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-nested-query.html). diff --git a/docs/overview/queries/elastic_query_range.md b/docs/overview/queries/elastic_query_range.md index 2da59b6e5..997369e96 100644 --- a/docs/overview/queries/elastic_query_range.md +++ b/docs/overview/queries/elastic_query_range.md @@ -3,4 +3,52 @@ id: elastic_query_range title: "Range Query" --- -TBD +A query that matches documents that contain terms within a provided range. + +In order to use the `Range` query import the following: +```scala +import zio.elasticsearch.query.RangeQuery +import zio.elasticsearch.ElasticQuery._ +``` + +You can create a `Range` query using the `range` method in the following manner: +```scala +val query: RangeQuery = range(field = "intField") +``` + +You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Range` query using the `range` method in the following manner: +```scala +val query: RangeQuery = range(field = Document.intField) +``` + +If you want to change `boost`, you can use the `boost` method: +```scala +val queryWithBoost: RangeQuery = range(field = Document.intField).boost(2.0) +``` + +If you want to change `format`, you can use the `format` method: +```scala +val queryWithFormat: RangeQuery = range(field = Document.dateField).format("yyyy-MM-dd") +``` + +If you want to change `gt` (greater than), you can use the `gt` method: +```scala +val queryWithGt: RangeQuery = range(field = Document.intField).gt(1) +``` + +If you want to change `gte` (greater than or equal to), you can use the `gte` method: +```scala +val queryWithGte: RangeQuery = range(field = Document.intField).gte(1) +``` + +If you want to change `lt` (less than), you can use the `lt` method: +```scala +val queryWithLt: RangeQuery = range(field = Document.intField).lt(100) +``` + +If you want to change `lte` (less than or equal to), you can use the `lte` method: +```scala +val queryWithLte: RangeQuery = range(field = Document.intField).lte(100) +``` + +You can find more information about Range Query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-range-query.html). diff --git a/docs/overview/queries/elastic_query_should.md b/docs/overview/queries/elastic_query_should.md deleted file mode 100644 index 61b993ff3..000000000 --- a/docs/overview/queries/elastic_query_should.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -id: elastic_query_should -title: "Should Query" ---- - -TBD diff --git a/docs/overview/queries/elastic_query_starts_with.md b/docs/overview/queries/elastic_query_starts_with.md deleted file mode 100644 index 2cc74d24f..000000000 --- a/docs/overview/queries/elastic_query_starts_with.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -id: elastic_query_starts_with -title: "Starts With Query" ---- - -TBD diff --git a/docs/overview/queries/elastic_query_term.md b/docs/overview/queries/elastic_query_term.md index d74b5101b..d87593a8f 100644 --- a/docs/overview/queries/elastic_query_term.md +++ b/docs/overview/queries/elastic_query_term.md @@ -3,4 +3,34 @@ id: elastic_query_term title: "Term Query" --- -TBD +The `Term` query returns documents that contain an exact term in a provided field. + +In order to use the `TermQuery` query import the following: +```scala +import zio.elasticsearch.query.TermQuery +import zio.elasticsearch.ElasticQuery._ +``` + +You can create a `Term` query using the `term` method this way: +```scala +val query: TermQuery = term(field = Document.name, value = "test") +``` + +You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Term` query using the `term` method this way: +```scala +val query: TermQuery = term(field = Document.name, value = "test") +``` + +If you want to change the `boost`, you can use `boost` method: +```scala +val queryWithBoost: TermQuery = term(field = Document.name, value = "test").boost(2.0) +``` + +If you want to change the `case_insensitive`, you can use `caseInsensitive`, `caseInsensitiveFalse` or `caseInsensitiveTrue` method: +```scala +val queryWithCaseInsensitive: TermQuery = term(field = Document.name, value = "test").caseInsensitive(true) +val queryWithCaseInsensitiveFalse: TermQuery = term(field = Document.name, value = "test").caseInsensitiveFalse +val queryWithCaseInsensitiveTrue: TermQuery = term(field = Document.name, value = "test").caseInsensitiveTrue +``` + +You can find more information about `Term` Query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-term-query.html). diff --git a/docs/overview/queries/elastic_query_terms.md b/docs/overview/queries/elastic_query_terms.md index d30754224..4acbf7814 100644 --- a/docs/overview/queries/elastic_query_terms.md +++ b/docs/overview/queries/elastic_query_terms.md @@ -3,4 +3,28 @@ id: elastic_query_terms title: "Terms Query" --- -TBD +The `Terms` query returns documents that contain one or more exact terms in a provided field. +This query is the same as the Term query, except you can search for multiple values. + +In order to use the `TermsQuery` query import the following: +```scala +import zio.elasticsearch.query.TermsQuery +import zio.elasticsearch.ElasticQuery._ +``` + +You can create a `Terms` query using the `terms` method this way: +```scala +val query: TermsQuery = terms(field = "name", "a", "b", "c") +``` + +You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Terms` query using the `terms` method this way: +```scala +val query: TermQuery = terms(field = Document.name, "a", "b", "c") +``` + +If you want to change the `boost`, you can use `boost` method: +```scala +val queryWithBoost: TermsQuery = terms(field = "name", "a", "b", "c").boost(2.0) +``` + +You can find more information about `Terms` Query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-terms-query.html). diff --git a/docs/overview/queries/elastic_query_wildcard.md b/docs/overview/queries/elastic_query_wildcard.md index 56ea05d43..c32d4d1de 100644 --- a/docs/overview/queries/elastic_query_wildcard.md +++ b/docs/overview/queries/elastic_query_wildcard.md @@ -3,4 +3,42 @@ id: elastic_query_wildcard title: "Wildcard Query" --- -TBD +The `Wildcard` query returns documents that contain terms matching a wildcard pattern. You can combine wildcard operators with other characters to create a wildcard pattern. + +In order to use the `Wildcard` query import the following: +```scala +import zio.elasticsearch.query.WildcardQuery +import zio.elasticsearch.ElasticQuery._ +``` + +The `Wildcard` query can be created with `contains`, `startsWith` or `wildcard` method. +The `contains` method is adjusted `wildcard` method, that returns documents that contain terms containing provided text. +The `startsWith` method is adjusted `wildcard` method that returns documents that contain terms starting with provided text. + +To create a `Wildcard` query use one of the following methods: +```scala +val query: WildcardQuery = contains(field = "name", value = "a") +val query: WildcardQuery = startsWith(field = "name", value = "a") +val query: WildcardQuery = wildcard(field = "name", value = "a*a*") +``` + +To create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Wildcard` query use one of the following methods: +```scala +val query: WildcardQuery = contains(field = Document.name, value = "a") +val query: WildcardQuery = startsWith(field = Document.name, value = "a") +val query: WildcardQuery = wildcard(field = Document.name, value = "a*a*") +``` + +If you want to change the `boost`, you can use `boost` method: +```scala +val queryWithBoost: WildcardQuery = contains(field = Document.name, value = "test").boost(2.0) +``` + +If you want to change the `case_insensitive`, you can use `caseInsensitive`, `caseInsensitiveFalse` or `caseInsensitiveTrue` method: +```scala +val queryWithCaseInsensitive: WildcardQuery = contains(field = Document.name, value = "a").caseInsensitive(true) +val queryWithCaseInsensitiveFalse: WildcardQuery = contains(field = Document.name, value = "a").caseInsensitiveFalse +val queryWithCaseInsensitiveTrue: WildcardQuery = contains(field = Document.name, value = "a").caseInsensitiveTrue +``` + +You can find more information about `Wildcard` Query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-wildcard-query.html#query-dsl-wildcard-query). diff --git a/docs/overview/zio_prelude_schema.md b/docs/overview/zio_prelude_schema.md index a00a03731..b7ad6a5c4 100644 --- a/docs/overview/zio_prelude_schema.md +++ b/docs/overview/zio_prelude_schema.md @@ -71,7 +71,6 @@ val result: RIO[Elasticsearch, SearchResult] = Elasticsearch.execute(request) ``` Accessors also have a `suffix` method, in case you want to use one in queries: - ```scala ElasticQuery.term("email.keyword", "jane.doe@lambdaworks.io") @@ -79,4 +78,8 @@ ElasticQuery.term("email.keyword", "jane.doe@lambdaworks.io") ElasticQuery.term(User.email.suffix("keyword"), "jane.doe@lambdaworks.io") ``` -In case the suffix is `"keyword"` or `"raw"` you can use `keyword` and `raw` methods respectively. +In case the suffix is `"keyword"` or `"raw"` you can use `keyword` and `raw` methods respectively: +```scala +ElasticQuery.term(User.email.keyword, "jane.doe@lambdaworks.io") +ElasticQuery.term(User.email.raw, "jane.doe@lambdaworks.io") +``` \ No newline at end of file diff --git a/modules/library/src/it/scala/zio/elasticsearch/HttpExecutorSpec.scala b/modules/library/src/it/scala/zio/elasticsearch/HttpExecutorSpec.scala index 895172881..208cc2218 100644 --- a/modules/library/src/it/scala/zio/elasticsearch/HttpExecutorSpec.scala +++ b/modules/library/src/it/scala/zio/elasticsearch/HttpExecutorSpec.scala @@ -578,7 +578,7 @@ object HttpExecutorSpec extends IntegrationSpec { .upsert[TestDocument](firstSearchIndex, thirdDocumentId, thirdDocumentUpdated) .refreshTrue ) - query = range(TestDocument.dateField).gte(LocalDate.now).format("uuuu-MM-dd").boost(1.0) + query = range(TestDocument.dateField).gte(LocalDate.now).format("yyyy-MM-dd").boost(1.0) res <- Executor.execute(ElasticRequest.search(firstSearchIndex, query)).documentAs[TestDocument] } yield assert(res)(equalTo(Chunk(secondDocumentUpdated, thirdDocumentUpdated))) } diff --git a/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala b/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala index 829aa5091..f7192bdd0 100644 --- a/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala +++ b/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala @@ -134,8 +134,6 @@ object ElasticQuery { * latitude of the desired point * @tparam S * document for which field query is executed - * @tparam A - * the type of value to be matched. A JSON decoder must be in scope for this type * @return * an instance of [[zio.elasticsearch.query.GeoDistanceQuery]] that represents `geo_distance` query to be performed. */ @@ -185,8 +183,6 @@ object ElasticQuery { * "drm3btev3e86") * @tparam S * document for which field query is executed - * @tparam A - * the type of value to be matched. A JSON decoder must be in scope for this type * @return * an instance of [[zio.elasticsearch.query.GeoDistanceQuery]] that represents `geo_distance` query to be performed. */ @@ -226,7 +222,8 @@ object ElasticQuery { * @param childType * a name of the child relationship mapped for the join field * @param query - * the [[ElasticQuery]] object representing query you wish to run on child documents of the child `type` field + * the type-safe [[ElasticQuery]] object representing query you wish to run on child documents of the child `type` + * field * @tparam S * document for which field query is executed * @return @@ -270,7 +267,8 @@ object ElasticQuery { * @param parentType * a name of the parent relationship mapped for the join field * @param query - * the [[ElasticQuery]] object representing query you wish to run on parent documents of the `parent_type` field + * the type-safe [[ElasticQuery]] object representing query you wish to run on parent documents of the `parent_type` + * field * @tparam S * document for which field query is executed * @return diff --git a/modules/library/src/main/scala/zio/elasticsearch/query/Queries.scala b/modules/library/src/main/scala/zio/elasticsearch/query/Queries.scala index d4bf9d415..3c60c0f7e 100644 --- a/modules/library/src/main/scala/zio/elasticsearch/query/Queries.scala +++ b/modules/library/src/main/scala/zio/elasticsearch/query/Queries.scala @@ -238,13 +238,17 @@ private[elasticsearch] final case class HasChild[S]( scoreMode: Option[ScoreMode] ) extends HasChildQuery[S] { self => - def ignoreUnmapped(value: Boolean): HasChildQuery[S] = self.copy(ignoreUnmapped = Some(value)) + def ignoreUnmapped(value: Boolean): HasChildQuery[S] = + self.copy(ignoreUnmapped = Some(value)) - def innerHits(innerHits: InnerHits): HasChildQuery[S] = self.copy(innerHitsField = Some(innerHits)) + def innerHits(innerHits: InnerHits): HasChildQuery[S] = + self.copy(innerHitsField = Some(innerHits)) - def maxChildren(value: Int): HasChildQuery[S] = self.copy(maxChildren = Some(value)) + def maxChildren(value: Int): HasChildQuery[S] = + self.copy(maxChildren = Some(value)) - def minChildren(value: Int): HasChildQuery[S] = self.copy(minChildren = Some(value)) + def minChildren(value: Int): HasChildQuery[S] = + self.copy(minChildren = Some(value)) def toJson(fieldPath: Option[String]): Json = Obj( @@ -261,7 +265,8 @@ private[elasticsearch] final case class HasChild[S]( ) ) - def scoreMode(value: ScoreMode): HasChildQuery[S] = self.copy(scoreMode = Some(value)) + def scoreMode(value: ScoreMode): HasChildQuery[S] = + self.copy(scoreMode = Some(value)) } sealed trait HasParentQuery[S] diff --git a/modules/library/src/test/scala/zio/elasticsearch/ElasticQuerySpec.scala b/modules/library/src/test/scala/zio/elasticsearch/ElasticQuerySpec.scala index 7a9542de0..847787f79 100644 --- a/modules/library/src/test/scala/zio/elasticsearch/ElasticQuerySpec.scala +++ b/modules/library/src/test/scala/zio/elasticsearch/ElasticQuerySpec.scala @@ -812,7 +812,7 @@ object ElasticQuerySpec extends ZIOSpecDefault { val queryInclusiveUpperBound = range(TestDocument.intField).lte(21) val queryMixedBounds = queryLowerBound.lte(21.0) val queryWithBoostParam = queryMixedBounds.boost(2.8) - val queryWithFormatParam = range(TestDocument.dateField).gt(LocalDate.of(2023, 5, 11)).format("uuuu-MM-dd") + val queryWithFormatParam = range(TestDocument.dateField).gt(LocalDate.of(2023, 5, 11)).format("yyyy-MM-dd") assert(query)( equalTo( @@ -931,7 +931,7 @@ object ElasticQuerySpec extends ZIOSpecDefault { lower = GreaterThan(LocalDate.of(2023, 5, 11)), upper = Unbounded, boost = None, - format = Some("uuuu-MM-dd") + format = Some("yyyy-MM-dd") ) ) ) @@ -2201,7 +2201,7 @@ object ElasticQuerySpec extends ZIOSpecDefault { val queryInclusiveUpperBound = range(TestDocument.intField).lte(45) val queryMixedBounds = range(TestDocument.intField).gt(10).lte(99) val queryMixedBoundsWithBoost = range(TestDocument.intField).gt(10).lte(99).boost(3.14) - val queryWithFormat = range(TestDocument.dateField).gt(LocalDate.of(2020, 1, 10)).format("uuuu-MM-dd") + val queryWithFormat = range(TestDocument.dateField).gt(LocalDate.of(2020, 1, 10)).format("yyyy-MM-dd") val expectedEmpty = """ @@ -2299,7 +2299,7 @@ object ElasticQuerySpec extends ZIOSpecDefault { | "range": { | "dateField": { | "gt": "2020-01-10", - | "format": "uuuu-MM-dd" + | "format": "yyyy-MM-dd" | } | } |} diff --git a/website/sidebars.js b/website/sidebars.js index 71b50e799..a213a317d 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -14,20 +14,16 @@ module.exports = { label: 'Elastic Query', items: [ 'overview/elastic_query', - 'overview/queries/elastic_query_contains', + 'overview/queries/elastic_query_bool', 'overview/queries/elastic_query_exists', - 'overview/queries/elastic_query_filter', + 'overview/queries/elastic_query_geo_distance', 'overview/queries/elastic_query_has_child', 'overview/queries/elastic_query_has_parent', + 'overview/queries/elastic_query_match', 'overview/queries/elastic_query_match_all', - 'overview/queries/elastic_query_matches', 'overview/queries/elastic_query_match_phrase', - 'overview/queries/elastic_query_must', - 'overview/queries/elastic_query_must_not', 'overview/queries/elastic_query_nested', 'overview/queries/elastic_query_range', - 'overview/queries/elastic_query_should', - 'overview/queries/elastic_query_starts_with', 'overview/queries/elastic_query_term', 'overview/queries/elastic_query_terms', 'overview/queries/elastic_query_wildcard',