Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(dsl): Support prefix query #258

Merged
merged 6 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/overview/queries/elastic_query_prefix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
id: elastic_query_prefix
title: "Prefix Query"
---

The `Prefix` query returns documents that contain a specific prefix in a provided field.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `Prefix` query returns documents that contain a specific prefix in a provided field.
The `Prefix` query returns documents that contain a specific prefix in the provided field.


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

You can create a `Prefix` query using the `prefix` method this way:
```scala
val query: PrefixQuery = prefix(field = Document.name, value = "test")
```

You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Prefix` query using the `prefix` method this way:
```scala
val query: PrefixQuery = prefix(field = Document.name, value = "test")
```

If you want to change the `case_insensitive`, you can use `caseInsensitive`, `caseInsensitiveFalse` or `caseInsensitiveTrue` method:
```scala
val queryWithCaseInsensitive: PrefixQuery = prefix(field = Document.name, value = "test").caseInsensitive(true)
val queryWithCaseInsensitiveFalse: PrefixQuery = prefix(field = Document.name, value = "test").caseInsensitiveFalse
val queryWithCaseInsensitiveTrue: PrefixQuery = prefix(field = Document.name, value = "test").caseInsensitiveTrue
```

You can find more information about `Prefix` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-prefix-query.html).
1 change: 1 addition & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {
'overview/queries/elastic_query_match_all',
'overview/queries/elastic_query_match_phrase',
'overview/queries/elastic_query_nested',
'overview/queries/elastic_query_prefix',
'overview/queries/elastic_query_range',
'overview/queries/elastic_query_term',
'overview/queries/elastic_query_terms',
Expand Down