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

Add website documentation for requests #227

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion docs/overview/queries/elastic_query_bool.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ If you want to change the `minimum_should_match` parameter, you can use the `min
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).
You can find more information about Boolean query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-bool-query.html).
2 changes: 1 addition & 1 deletion docs/overview/queries/elastic_query_range.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ If you want to change `lte` (less than or equal to), you can use the `lte` metho
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).
You can find more information about Range query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-range-query.html).
2 changes: 1 addition & 1 deletion docs/overview/queries/elastic_query_term.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ val queryWithCaseInsensitiveFalse: TermQuery = term(field = Document.name, value
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).
You can find more information about `Term` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-term-query.html).
2 changes: 1 addition & 1 deletion docs/overview/queries/elastic_query_terms.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ If you want to change the `boost`, you can use `boost` method:
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).
You can find more information about `Terms` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-terms-query.html).
2 changes: 1 addition & 1 deletion docs/overview/queries/elastic_query_wildcard.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ val queryWithCaseInsensitiveFalse: WildcardQuery = contains(field = Document.nam
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).
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).
15 changes: 14 additions & 1 deletion docs/overview/requests/elastic_request_aggregate.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,17 @@ id: elastic_request_aggregate
title: "Aggregation Request"
---

TBD
This request is used to create aggregations which summarizes your data as metrics, statistics, or other analytics.

To create a `Aggregate` request do the following:
```scala
import zio.elasticsearch.ElasticRequest.AggregateRequest
import zio.elasticsearch.ElasticRequest.aggregate
// this import is required for using `IndexName`
import zio.elasticsearch._
import zio.elasticsearch.ElasticAggregation._

val request: AggregateRequest = aggregate(name = IndexName("index"), aggregation = maxAggregation(name = "aggregation", field = "intField"))
```

You can find more information about `Aggregate` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations.html).
38 changes: 37 additions & 1 deletion docs/overview/requests/elastic_request_bulk.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,40 @@ id: elastic_request_bulk
title: "Bulk Request"
---

TBD
The `Bulk` request performs multiple indexing or delete operations in a single API call. This reduces overhead and can greatly increase indexing speed.

In order to use the `Bulk` request import the following:
```scala
import zio.elasticsearch.ElasticRequest.BulkRequest
import zio.elasticsearch.ElasticRequest.bulk
```

You can create a `Bulk` request using the `bulk` method this way:
```scala
// this import is required for using `IndexName` and `DocumentId`
import zio.elasticsearch._

val index = Index("index")

val document1 = new Document(id = DocumentId("111"), intField = 1, stringField = "stringField1")
val document2 = new Document(id = DocumentId("222"), intField = 2, stringField = "stringField2")

val request: BulkRequest = bulk(create(index = index, doc = document1), upsert(index = index, id = DocumentId("111"), doc = document2))
```

If you want to change the `refresh`, you can use `refresh`, `refreshFalse` or `refreshTrue` method:
```scala
val requestWithRefresh: BulkRequest = bulk(create(index = index, doc = document1), upsert(index = index, id = DocumentId("111"), doc = document2)).refresh(true)
val requestWithRefreshFalse: BulkRequest = bulk(create(index = index, doc = document1), upsert(index = index, id = DocumentId("111"), doc = document2)).refreshFalse
val requestWithRefreshTrue: BulkRequest = bulk(create(index = index, doc = document1), upsert(index = index, id = DocumentId("111"), doc = document2)).refreshTrue
```

If you want to change the `routing`, you can use the `routing` method:
```scala
// this import is required for using `Routing` also
import zio.elasticsearch._

val requestWithRouting: BulkRequest = bulk(create(index = index, doc = document1), upsert(index = index, id = DocumentId("111"), doc = document2)).routing(Routing("routing"))
```

You can find more information about `Bulk` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/docs-bulk.html).
33 changes: 32 additions & 1 deletion docs/overview/requests/elastic_request_count.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,35 @@ id: elastic_request_count
title: "Count Request"
---

TBD
The `Count` request is used for getting the number of matches for a search query. If no query is specified, `matchAll` query will be used to count all the documents.

In order to use the `Count` request import the following:
```scala
import zio.elasticsearch.ElasticRequest.CountRequest
import zio.elasticsearch.ElasticRequest.count
```

You can create a `Count` request using the `count` method without specifying query this way:
```scala
// this import is required for using `IndexName`
import zio.elasticsearch._

val request: CountRequest = count(index = IndexName("index"))
```

You can create a `Count` request using the `count` method with specified query this way:
```scala
import zio.elasticsearch.ElasticQuery._

val request: CountRequest = count(index = IndexName("index"), query = contains(field = Document.name, value = "test"))
```

If you want to change the `routing`, you can use the `routing` method:
```scala
// this import is required for using `Routing` also
import zio.elasticsearch._

val requestWithRouting: CountRequest = count(index = Index("index")).routing(Routing("routing"))
```

You can find more information about `Count` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-count.html).
80 changes: 78 additions & 2 deletions docs/overview/requests/elastic_request_create.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,82 @@
---
id: elastic_request_create
title: "Create Request"
title: "Create Request, CreateWithId Request and CreateOrUpdate Request"
---

TBD
The `Create`, the `CreateWithId` and the `CreateOrUpdate` requests add a JSON document to the specified data stream and make it searchable.

There are three ways of adding documents to the Elasticsearch index:
1. By using `Create` request - creates a JSON document without specifying ID (Elasticsearch creates one)
2. By using `CreateWithId` request - creates a JSON document with specified ID
3. By using `CreateOrUpdate` request - creates JSON document with specified ID, or updates the document (if it already exists)

In order to use the `Create` request import the following:
```scala
import zio.elasticsearch.ElasticRequest.CreateRequest
import zio.elasticsearch.ElasticRequest.create
```

In order to use the `CreateWithId` request import the following:
```scala
import zio.elasticsearch.ElasticRequest.CreateWithIdRequest
import zio.elasticsearch.ElasticRequest.create
```

In order to use the `CreateOrUpdate` request import the following:
```scala
import zio.elasticsearch.ElasticRequest.CreateOrUpdateRequest
import zio.elasticsearch.ElasticRequest.upsert
```

Except imports, you must specify a document you want to create, with its implicit schema.
```scala
import zio.schema.Schema
// example of document
final case class User(id: String, username: String)

val user: User = User(id = "1", username = "johndoe")

implicit val schema: Schema.CaseClass2[String, String, User] = DeriveSchema.gen[GitHubRepo]
```

You can create a `Create` request using the `create` method this way:
```scala
// this import is required for using `IndexName`
import zio.elasticsearch._

val request: CreateRequest = create(index = IndexName("index"), doc = user)
```

You can create a `CreateWithId` request using the `create` method this way:
```scala
// this import is required for using `DocumentId` also
import zio.elasticsearch._

val request: CreateWithIdRequest = create(index = IndexName("index"), id = DocumentId("documentId"), doc = user)
```

You can create a `CreateOrUpdate` request using the `upsert` method this way:
```scala
import zio.elasticsearch._

val request: CreateOrUpdateRequest = upsert(index = IndexName("index"), id = DocumentId("documentId"), doc = user)
```

If you want to change the `refresh`, you can use `refresh`, `refreshFalse` or `refreshTrue` method on any of previously mentioned requests:
```scala
val requestWithRefresh: CreateRequest = create(index = IndexName("index"), doc = user).refresh(true)
val requestWithRefreshFalse: CreateWithIdRequest = create(index = IndexName("index"), id = DocumentId("documentId"), doc = user).refreshFalse
val requestWithRefreshTrue: CreateOrUpdateRequest = upsert(index = IndexName("index"), id = DocumentId("documentId"), doc = user).refreshTrue
```

If you want to change the `routing`, you can use the `routing` method on any of previously mentioned requests:
```scala
// this import is required for using `Routing` also
import zio.elasticsearch._

val request1WithRouting: CreateRequest = create(index = IndexName("index"), doc = user).routing(Routing("routing"))
val request2WithRouting: CreateWithIdRequest = create(index = IndexName("index"), id = DocumentId("documentId"), doc = user).routing(Routing("routing"))
val request3WithRouting: CreateOrUpdateRequest = upsert(index = IndexName("index"), id = DocumentId("documentId"), doc = user).routing(Routing("routing"))
```

You can find more information about `Create`, `CreateWithId`, `CreateOrUpdate` requests [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/docs-index_.html).
23 changes: 22 additions & 1 deletion docs/overview/requests/elastic_request_create_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,25 @@ id: elastic_request_create_index
title: "Create Index Request"
---

TBD
This request creates a new Elasticsearch index.

In order to use the `CreateIndex` request import the following:
```scala
import zio.elasticsearch.ElasticRequest.CreateIndexRequest
import zio.elasticsearch.ElasticRequest.createIndex
```

You can create a `CreateIndex` request using the `createIndex` method in the following manner:
```scala
// this import is required for using `IndexName`
import zio.elasticsearch._

val request: CreateIndexRequest = createIndex(name = IndexName("index"))
```

You can also create a `CreateIndex` request using the `createIndex` method with the specific definition in the following manner:
```scala
val request: CreateIndexRequest = createIndex(name = IndexName("index"), definition = """{ "mappings": { "properties": { "subDocumentList": { "type": "nested" } } } }""")
```

You can find more information about `CreateIndex` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/indices-create-index.html).
29 changes: 28 additions & 1 deletion docs/overview/requests/elastic_request_delete_by_id.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,31 @@ id: elastic_request_delete_by_id
title: "Delete By ID Request"
---

TBD
This query removes a JSON document from the specified index.

To create a `DeleteById` request do the following:
```scala
import zio.elasticsearch.ElasticRequest.DeleteByIdRequest
import zio.elasticsearch.ElasticRequest.deleteById
// this import is required for using `IndexName` and `DocumentId`
import zio.elasticsearch._

val request: DeleteByIdRequest = deleteById(index = IndexName("index"), id = DocumentId("111"))
```

If you want to change the `refresh`, you can use `refresh`, `refreshFalse` or `refreshTrue` method:
```scala
val requestWithRefresh: DeleteByIdRequest = deleteById(index = IndexName("index"), id = DocumentId("111")).refresh(true)
val requestWithRefreshFalse: DeleteByIdRequest = deleteById(index = IndexName("index"), id = DocumentId("111")).refreshFalse
val requestWithRefreshTrue: DeleteByIdRequest = deleteById(index = IndexName("index"), id = DocumentId("111")).refreshTrue
```

If you want to change the `routing`, you can use the `routing` method:
```scala
// this import is required for `Routing` also
import zio.elasticsearch._

val requestWithRouting: DeleteByIdRequest = deleteById(index = IndexName("index"), id = DocumentId("111")).routing(Routing("routing"))
```

You can find more information about `DeleteById` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/docs-delete.html).
30 changes: 29 additions & 1 deletion docs/overview/requests/elastic_request_delete_by_query.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,32 @@ id: elastic_request_delete_by_query
title: "Delete By Query Request"
---

TBD
The `DeleteByQuery` request deletes documents that match the specified query.

To create a `DeleteById` request do the following:
```scala
import zio.elasticsearch.ElasticRequest.DeleteByQueryRequest
import zio.elasticsearch.ElasticRequest.deleteByQuery
// this import is required for using `IndexName`
import zio.elasticsearch._
import zio.elasticsearch.ElasticQuery._

val request: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test"))
```

If you want to change the `refresh`, you can use `refresh`, `refreshFalse` or `refreshTrue` method:
```scala
val requestWithRefresh: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test")).refresh(true)
val requestWithRefreshFalse: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test")).refreshFalse
val requestWithRefreshTrue: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test")).refreshTrue
```

If you want to change the `routing`, you can use the `routing` method:
```scala
// this import is required for `Routing` also
import zio.elasticsearch._

val requestWithRouting: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test")).routing(Routing("routing"))
```

You can find more information about `DeleteByQuery` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/docs-delete-by-query.html).
14 changes: 13 additions & 1 deletion docs/overview/requests/elastic_request_delete_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,16 @@ id: elastic_request_delete_index
title: "Delete Index Request"
---

TBD
This request deletes specified Elasticsearch index.

To create a `DeleteById` request do the following:
```scala
import zio.elasticsearch.ElasticRequest.DeleteIndexRequest
import zio.elasticsearch.ElasticRequest.deleteIndex
// this import is required for using `IndexName`
import zio.elasticsearch._

val request: DeleteIndexRequest = deleteIndex(name = IndexName("index"))
```

You can find more information about `DeleteIndex` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/indices-delete-index.html).
22 changes: 21 additions & 1 deletion docs/overview/requests/elastic_request_exists.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,24 @@ id: elastic_request_exists
title: "Exists Request"
---

TBD
This request is used for checking whether document exists.

To create a `Exists` request do the following:
```scala
import zio.elasticsearch.ElasticRequest.ExistsRequest
import zio.elasticsearch.ElasticRequest.exists
// this import is required for using `IndexName` and `DocumentId`
import zio.elasticsearch._

val request: ExistsRequest = exists(index = IndexName("index"), id = DocumentId("111"))
```

If you want to change the `routing`, you can use the `routing` method:
```scala
// this import is required for `Routing` also
import zio.elasticsearch._

val requestWithRouting: ExistsRequest = exists(index = IndexName("index"), id = DocumentId("111")).routing(Routing("routing"))
```

You can find more information about `Exists` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/indices-exists.html#indices-exists).
29 changes: 28 additions & 1 deletion docs/overview/requests/elastic_request_get_by_id.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,31 @@ id: elastic_request_get_by_id
title: "Get By ID Request"
---

TBD
The `GetById` request retrieves the specified JSON document from an Elasticsearch index.

To create a `GetById` request do the following:
```scala
import zio.elasticsearch.ElasticRequest.GetByIdRequest
import zio.elasticsearch.ElasticRequest.getById
// this import is required for using `IndexName` and `DocumentId`
import zio.elasticsearch._

val request: ExistsRequest = getById(index = IndexName("index"), id = DocumentId("111"))
```

If you want to change the `refresh`, you can use `refresh`, `refreshFalse` or `refreshTrue` method:
```scala
val requestWithRefresh: GetByIdRequest = getById(index = IndexName("index"), id = DocumentId("111")).refresh(true)
val requestWithRefreshFalse: GetByIdRequest = getById(index = IndexName("index"), id = DocumentId("111")).refreshFalse
val requestWithRefreshTrue: GetByIdRequest = getById(index = IndexName("index"), id = DocumentId("111")).refreshTrue
```

If you want to change the `routing`, you can use the `routing` method:
```scala
// this import is required for `Routing` also
import zio.elasticsearch._

val requestWithRouting: GetByIdRequest = getById(index = IndexName("index"), id = DocumentId("111")).routing(Routing("routing"))
```

You can find more information about `GetById` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/docs-get.html).
Loading