├── website ├── static │ ├── .nojekyll │ └── img │ │ └── favicon.png ├── babel.config.js ├── src │ ├── components │ │ └── HomepageFeatures │ │ │ ├── styles.module.css │ │ │ └── index.js │ ├── pages │ │ ├── index.module.css │ │ └── index.js │ └── css │ │ └── custom.css └── package.json ├── .gitattributes ├── project ├── build.properties └── plugins.sbt ├── .gitignore ├── .github ├── CODEOWNERS ├── mergify.yml ├── workflows │ ├── auto-approve.yml │ └── site.yml └── renovate.json ├── modules ├── example │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.conf │ │ │ └── mapping.json │ │ │ └── scala │ │ │ └── example │ │ │ ├── config │ │ │ ├── HttpConfig.scala │ │ │ ├── ElasticsearchConfig.scala │ │ │ └── AppConfig.scala │ │ │ ├── package.scala │ │ │ ├── api │ │ │ ├── ErrorResponseData.scala │ │ │ ├── HealthCheck.scala │ │ │ ├── package.scala │ │ │ └── ErrorResponse.scala │ │ │ ├── external │ │ │ └── github │ │ │ │ ├── model │ │ │ │ ├── RepoOwner.scala │ │ │ │ └── RepoResponse.scala │ │ │ │ └── RepoFetcher.scala │ │ │ └── GitHubRepo.scala │ └── README.md └── library │ └── src │ ├── test │ ├── scala-2 │ │ └── zio │ │ │ └── elasticsearch │ │ │ └── utils │ │ │ └── UnsafeWrapUtil.scala │ ├── scala-3 │ │ └── zio │ │ │ └── elasticsearch │ │ │ └── utils │ │ │ └── UnsafeWrapUtil.scala │ └── scala │ │ └── zio │ │ └── elasticsearch │ │ ├── utils │ │ └── package.scala │ │ ├── domain │ │ ├── TestNestedField.scala │ │ ├── PartialTestSubDocument.scala │ │ ├── PartialTestDocument.scala │ │ ├── TestSubDocument.scala │ │ └── TestDocument.scala │ │ └── ElasticPrimitiveSpec.scala │ └── main │ ├── scala │ └── zio │ │ └── elasticsearch │ │ ├── query │ │ ├── package.scala │ │ ├── GeoHash.scala │ │ ├── ScoreMode.scala │ │ ├── sort │ │ │ ├── Missing.scala │ │ │ ├── SortOrder.scala │ │ │ ├── SourceType.scala │ │ │ ├── options │ │ │ │ ├── HasFormat.scala │ │ │ │ ├── HasUnmappedType.scala │ │ │ │ ├── HasOrder.scala │ │ │ │ ├── HasMissing.scala │ │ │ │ ├── HasNumericType.scala │ │ │ │ └── HasMode.scala │ │ │ ├── NumericType.scala │ │ │ └── SortMode.scala │ │ ├── options │ │ │ ├── HasBoost.scala │ │ │ ├── HasMinimumShouldMatch.scala │ │ │ ├── HasInnerHits.scala │ │ │ ├── HasScoreMode.scala │ │ │ ├── HasIgnoreUnmapped.scala │ │ │ └── HasCaseInsensitive.scala │ │ └── MultiMatchType.scala │ │ ├── executor │ │ ├── ElasticCredentials.scala │ │ └── response │ │ │ ├── Total.scala │ │ │ ├── InnerHitsResponse.scala │ │ │ ├── Shards.scala │ │ │ ├── CreateResponse.scala │ │ │ ├── CountResponse.scala │ │ │ ├── GetResponse.scala │ │ │ ├── BulkResponse.scala │ │ │ ├── Hits.scala │ │ │ ├── Error.scala │ │ │ ├── UpdateByQueryResponse.scala │ │ │ └── Hit.scala │ │ ├── aggregation │ │ ├── AggregationOrder.scala │ │ └── options │ │ │ ├── HasSize.scala │ │ │ ├── WithSubAgg.scala │ │ │ ├── WithAgg.scala │ │ │ └── HasMissing.scala │ │ ├── request │ │ ├── UpdateOutcome.scala │ │ ├── DeletionOutcome.scala │ │ ├── CreationOutcome.scala │ │ ├── IsExecutable.scala │ │ ├── UpdateConflicts.scala │ │ ├── options │ │ │ ├── HasSize.scala │ │ │ ├── HasSearchAfter.scala │ │ │ ├── HasRouting.scala │ │ │ ├── HasHighlights.scala │ │ │ ├── HasFrom.scala │ │ │ ├── HasSort.scala │ │ │ └── HasRefresh.scala │ │ └── Document.scala │ │ ├── data │ │ └── GeoPoint.scala │ │ ├── ElasticExecutor.scala │ │ ├── script │ │ └── options │ │ │ ├── HasParams.scala │ │ │ └── HasLang.scala │ │ ├── result │ │ ├── UpdateByQueryResult.scala │ │ └── ElasticException.scala │ │ ├── ElasticConfig.scala │ │ └── StreamConfig.scala │ ├── scala-2 │ └── zio │ │ └── elasticsearch │ │ ├── RoutingNewtype.scala │ │ ├── IndexNameValidation.scala │ │ ├── IndexPatternValidation.scala │ │ ├── IndexNameNewtype.scala │ │ ├── IndexPatternNewtype.scala │ │ └── MultiIndex.scala │ └── scala-3 │ └── zio │ └── elasticsearch │ ├── RoutingNewtype.scala │ ├── IndexNameNewtype.scala │ ├── IndexPatternNewtype.scala │ ├── IndexNameValidator.scala │ └── IndexPatternValidator.scala ├── docs ├── about │ ├── index.md │ └── contributing.md └── overview │ ├── requests │ ├── elastic_request_delete_index.md │ ├── elastic_request_exists.md │ ├── elastic_request_create_index.md │ ├── elastic_request_refresh.md │ ├── elastic_request_count.md │ ├── elastic_request_aggregate.md │ ├── elastic_request_get_by_id.md │ ├── elastic_request_delete_by_id.md │ └── elastic_request_delete_by_query.md │ ├── queries │ ├── elastic_query_match_all.md │ ├── elastic_query_ids.md │ ├── elastic_query_exists.md │ ├── elastic_query_match.md │ ├── elastic_query_terms.md │ ├── elastic_query_match_phrase.md │ ├── elastic_query_match_phrase_prefix.md │ ├── elastic_query_boosting.md │ ├── elastic_query_prefix.md │ ├── elastic_query_regexp.md │ ├── elastic_query_match_boolean_prefix.md │ ├── elastic_query_constant_score.md │ ├── elastic_query_term.md │ ├── elastic_query_fuzzy.md │ ├── elastic_query_geo_polygon.md │ ├── elastic_query_simple_query_string.md │ ├── elastic_query_disjunction_max.md │ ├── elastic_query_nested.md │ ├── elastic_query_has_child.md │ ├── elastic_query_has_parent.md │ ├── elastic_query_range.md │ ├── elastic_query_multi_match.md │ └── elastic_query_wildcard.md │ ├── usage.md │ ├── installation.md │ ├── bulkable.md │ ├── aggregations │ ├── elastic_aggregation_bucket_selector.md │ ├── elastic_aggregation_missing.md │ ├── elastic_aggregation_value_count.md │ ├── elastic_aggregation_max.md │ ├── elastic_aggregation_sum.md │ ├── elastic_aggregation_avg.md │ ├── elastic_aggregation_min.md │ ├── elastic_aggregation_bucket_sort.md │ ├── elastic_aggregation_cardinality.md │ ├── elastic_aggregation_stats.md │ ├── elastic_aggregation_filter.md │ ├── elastic_aggregation_sampler.md │ ├── elastic_aggregation_percentile_ranks.md │ └── elastic_aggregation_percentiles.md │ ├── index.md │ ├── elastic_executor.md │ └── fluent_api.md ├── docker ├── elasticsearch-7.x.yml └── elasticsearch-8.x.yml ├── .git-blame-ignore-revs ├── .scalafix.conf └── .scalafmt.conf /website/static/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | sbt linguist-vendored 2 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version = 1.11.7 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | 3 | website/.docusaurus 4 | website/node_modules 5 | website/package-lock.json 6 | website/build 7 | -------------------------------------------------------------------------------- /website/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')], 3 | }; 4 | -------------------------------------------------------------------------------- /website/static/img/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lambdaworks/zio-elasticsearch/HEAD/website/static/img/favicon.png -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | .github/workflows/ @drmarjanovic @mvelimir 2 | build.sbt @drmarjanovic @mvelimir 3 | project/BuildHelper.scala @drmarjanovic @mvelimir 4 | -------------------------------------------------------------------------------- /modules/example/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | http { 2 | port = 9000 3 | } 4 | 5 | elasticsearch { 6 | host = "localhost" 7 | port = 9200 8 | } 9 | -------------------------------------------------------------------------------- /docs/about/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: about_index 3 | title: "About ZIO Elasticsearch" 4 | --- 5 | 6 | ZIO Elasticsearch is a type-safe and streaming-friendly ZIO-native Elasticsearch client. 7 | -------------------------------------------------------------------------------- /website/src/components/HomepageFeatures/styles.module.css: -------------------------------------------------------------------------------- 1 | .features { 2 | display: flex; 3 | align-items: center; 4 | padding: 2rem 0; 5 | width: 100%; 6 | } 7 | 8 | .featureSvg { 9 | height: 200px; 10 | width: 200px; 11 | } 12 | -------------------------------------------------------------------------------- /modules/library/src/test/scala-2/zio/elasticsearch/utils/UnsafeWrapUtil.scala: -------------------------------------------------------------------------------- 1 | package zio.elasticsearch.utils 2 | 3 | import zio.prelude.Newtype 4 | 5 | abstract class UnsafeWrapUtil { 6 | def unsafeWrap[A, T <: Newtype[A]](value: A)(newtype: T): newtype.Type = Newtype.unsafeWrap(newtype)(value) 7 | } 8 | -------------------------------------------------------------------------------- /modules/library/src/test/scala-3/zio/elasticsearch/utils/UnsafeWrapUtil.scala: -------------------------------------------------------------------------------- 1 | package zio.elasticsearch.utils 2 | 3 | import zio.prelude.{Newtype, NewtypeCustom} 4 | 5 | abstract class UnsafeWrapUtil { 6 | def unsafeWrap[A, T <: Newtype[A] | NewtypeCustom[A]](value: A)(newtype: T): newtype.Type = newtype.wrap(value) 7 | } 8 | -------------------------------------------------------------------------------- /docker/elasticsearch-7.x.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | 3 | services: 4 | elasticsearch: 5 | image: elasticsearch:7.17.16 6 | container_name: zio-elasticsearch-test 7 | ports: 8 | - "9200:9200" 9 | environment: 10 | discovery.type: "single-node" 11 | xpack.security.enabled: "false" 12 | ES_JAVA_OPTS: "-Xms512m -Xmx512m" 13 | -------------------------------------------------------------------------------- /docker/elasticsearch-8.x.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | 3 | services: 4 | elasticsearch: 5 | image: elasticsearch:8.12.0 6 | container_name: zio-elasticsearch-8-test 7 | ports: 8 | - "9200:9200" 9 | environment: 10 | discovery.type: "single-node" 11 | xpack.security.enabled: "false" 12 | ES_JAVA_OPTS: "-Xms512m -Xmx512m" 13 | -------------------------------------------------------------------------------- /website/src/pages/index.module.css: -------------------------------------------------------------------------------- 1 | .heroBanner { 2 | padding: 4rem 0; 3 | text-align: center; 4 | position: relative; 5 | overflow: hidden; 6 | } 7 | 8 | @media screen and (max-width: 996px) { 9 | .heroBanner { 10 | padding: 2rem; 11 | } 12 | } 13 | 14 | .buttons { 15 | display: flex; 16 | align-items: center; 17 | justify-content: center; 18 | } 19 | -------------------------------------------------------------------------------- /modules/library/src/test/scala/zio/elasticsearch/utils/package.scala: -------------------------------------------------------------------------------- 1 | package zio.elasticsearch 2 | 3 | import zio.json.DecoderOps 4 | import zio.json.ast.Json 5 | 6 | package object utils extends UnsafeWrapUtil { 7 | 8 | final implicit class RichString(private val text: String) extends AnyVal { 9 | def toJson: Json = text.fromJson[Json].toOption.get 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # Scala Steward: Reformat with scalafmt 3.7.15 2 | b88124837b4632490181bbe02aa345a0292a9808 3 | 4 | # Scala Steward: Reformat with scalafmt 3.8.0 5 | ae7ede210c5b46ae1bc58a21b74f5d3e12937d43 6 | 7 | # Scala Steward: Reformat with scalafmt 3.8.2 8 | e951ceb447a24ccf320f7547524496006b4978a1 9 | 10 | # Scala Steward: Reformat with scalafmt 3.9.7 11 | 1e8d7ad5ccea6ea8bd05910a21071e585504e354 12 | -------------------------------------------------------------------------------- /.scalafix.conf: -------------------------------------------------------------------------------- 1 | rules = [ 2 | DisableSyntax 3 | ExplicitResultTypes 4 | LeakingImplicitClassVal 5 | NoAutoTupling 6 | NoValInForComprehension 7 | OrganizeImports 8 | ProcedureSyntax 9 | RemoveUnused 10 | ] 11 | 12 | OrganizeImports { 13 | # Align with IntelliJ IDEA so that they don't fight each other 14 | groupedImports = Merge 15 | } 16 | 17 | RemoveUnused { 18 | imports = false // handled by OrganizeImports 19 | } 20 | -------------------------------------------------------------------------------- /.github/mergify.yml: -------------------------------------------------------------------------------- 1 | pull_request_rules: 2 | - name: Automatic merge of Scala Steward PRs 3 | conditions: 4 | - author=scala-steward 5 | - "#approved-reviews-by>=1" 6 | - check-success=ci 7 | actions: 8 | merge: 9 | method: squash 10 | 11 | - name: Automatic merge of Renovate PRs 12 | conditions: 13 | - author=renovate[bot] 14 | - "#approved-reviews-by>=1" 15 | - check-success=ci 16 | actions: 17 | merge: 18 | method: squash 19 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.14.5") 2 | addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.13.1") 3 | addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.11.2") 4 | addSbtPlugin("com.github.sbt" % "sbt-unidoc" % "0.6.0") 5 | addSbtPlugin("com.github.sbt" % "sbt-header" % "5.11.0") 6 | addSbtPlugin("io.spray" % "sbt-revolver" % "0.10.0") 7 | addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.8.1") 8 | addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6") 9 | -------------------------------------------------------------------------------- /modules/library/src/test/scala/zio/elasticsearch/domain/TestNestedField.scala: -------------------------------------------------------------------------------- 1 | package zio.elasticsearch.domain 2 | 3 | import zio.elasticsearch.FieldAccessorBuilder 4 | import zio.schema.{DeriveSchema, Schema} 5 | 6 | final case class TestNestedField(stringField: String, longField: Long) 7 | 8 | object TestNestedField { 9 | implicit val schema: Schema.CaseClass2[String, Long, TestNestedField] = DeriveSchema.gen[TestNestedField] 10 | 11 | val (stringField, longField) = schema.makeAccessors(FieldAccessorBuilder) 12 | } 13 | -------------------------------------------------------------------------------- /modules/library/src/test/scala/zio/elasticsearch/domain/PartialTestSubDocument.scala: -------------------------------------------------------------------------------- 1 | package zio.elasticsearch.domain 2 | 3 | import zio.elasticsearch.FieldAccessorBuilder 4 | import zio.schema.{DeriveSchema, Schema} 5 | 6 | final case class PartialTestSubDocument(stringField: String, intFieldList: List[Int]) 7 | 8 | object PartialTestSubDocument { 9 | implicit val schema: Schema.CaseClass2[String, List[Int], PartialTestSubDocument] = 10 | DeriveSchema.gen[PartialTestSubDocument] 11 | 12 | val (stringField, intFieldList) = schema.makeAccessors(FieldAccessorBuilder) 13 | } 14 | -------------------------------------------------------------------------------- /.scalafmt.conf: -------------------------------------------------------------------------------- 1 | version = "3.10.2" 2 | maxColumn = 120 3 | align.preset = most 4 | align.multiline = false 5 | continuationIndent.defnSite = 2 6 | assumeStandardLibraryStripMargin = true 7 | docstrings.style = Asterisk 8 | lineEndings = preserve 9 | includeCurlyBraceInSelectChains = false 10 | danglingParentheses.preset = true 11 | optIn.annotationNewlines = true 12 | newlines.alwaysBeforeMultilineDef = false 13 | runner.dialect = scala213 14 | rewrite.rules = [RedundantBraces] 15 | rewrite.redundantBraces.generalExpressions = false 16 | rewriteTokens = { 17 | "⇒": "=>" 18 | "→": "->" 19 | "←": "<-" 20 | } 21 | -------------------------------------------------------------------------------- /.github/workflows/auto-approve.yml: -------------------------------------------------------------------------------- 1 | name: Auto Approve 2 | 3 | on: 4 | pull_request_target: 5 | 6 | jobs: 7 | auto-approve: 8 | runs-on: ubuntu-24.04 9 | if: github.actor == 'scala-steward' || github.actor == 'renovate[bot]' 10 | steps: 11 | - name: Auto approve 12 | uses: hmarr/auto-approve-action@v4.0.0 13 | with: 14 | github-token: "${{ secrets.AUTO_APPROVE_GITHUB_ACCESS_TOKEN }}" 15 | - name: Auto approve 1 16 | uses: hmarr/auto-approve-action@v4.0.0 17 | with: 18 | github-token: "${{ secrets.AUTO_APPROVE_GITHUB_ACCESS_TOKEN_1 }}" 19 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "commitMessageAction": "Update", 3 | "commitMessageTopic": " {{depName}}", 4 | "packageRules": [ 5 | { 6 | "matchManagers": [ 7 | "sbt" 8 | ], 9 | "enabled": false 10 | }, 11 | { 12 | "matchManagers": [ 13 | "docker-compose" 14 | ], 15 | "matchPackagePatterns": [ 16 | "elasticsearch" 17 | ], 18 | "matchUpdateTypes": [ 19 | "major" 20 | ], 21 | "enabled": false 22 | } 23 | ], 24 | "rebaseWhen": "conflicted", 25 | "schedule": [ 26 | "after 6pm every weekday", 27 | "every weekend" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /modules/library/src/test/scala/zio/elasticsearch/domain/PartialTestDocument.scala: -------------------------------------------------------------------------------- 1 | package zio.elasticsearch.domain 2 | 3 | import zio.elasticsearch.FieldAccessorBuilder 4 | import zio.schema.{DeriveSchema, Schema} 5 | 6 | final case class PartialTestDocument( 7 | stringField: String, 8 | subDocumentList: List[PartialTestSubDocument], 9 | intField: Int 10 | ) 11 | 12 | object PartialTestDocument { 13 | implicit val schema: Schema.CaseClass3[String, List[PartialTestSubDocument], Int, PartialTestDocument] = 14 | DeriveSchema.gen[PartialTestDocument] 15 | 16 | val (stringField, subDocumentList, intField) = schema.makeAccessors(FieldAccessorBuilder) 17 | } 18 | -------------------------------------------------------------------------------- /modules/library/src/test/scala/zio/elasticsearch/domain/TestSubDocument.scala: -------------------------------------------------------------------------------- 1 | package zio.elasticsearch.domain 2 | 3 | import zio.elasticsearch.FieldAccessorBuilder 4 | import zio.schema.{DeriveSchema, Schema} 5 | 6 | final case class TestSubDocument( 7 | stringField: String, 8 | nestedField: TestNestedField, 9 | intField: Int, 10 | intFieldList: List[Int] 11 | ) 12 | 13 | object TestSubDocument { 14 | implicit val schema: Schema.CaseClass4[String, TestNestedField, Int, List[Int], TestSubDocument] = 15 | DeriveSchema.gen[TestSubDocument] 16 | 17 | val (stringField, nestedField, intField, intFieldList) = schema.makeAccessors(FieldAccessorBuilder) 18 | } 19 | -------------------------------------------------------------------------------- /docs/overview/requests/elastic_request_delete_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_request_delete_index 3 | title: "Delete Index Request" 4 | --- 5 | 6 | This request deletes specified Elasticsearch index. 7 | 8 | To create a `DeleteById` request do the following: 9 | ```scala 10 | import zio.elasticsearch.ElasticRequest.DeleteIndexRequest 11 | import zio.elasticsearch.ElasticRequest.deleteIndex 12 | // this import is required for using `IndexName` 13 | import zio.elasticsearch._ 14 | 15 | val request: DeleteIndexRequest = deleteIndex(name = IndexName("index")) 16 | ``` 17 | 18 | You can find more information about `DeleteIndex` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/indices-delete-index.html). 19 | -------------------------------------------------------------------------------- /.github/workflows/site.yml: -------------------------------------------------------------------------------- 1 | name: Website 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'main' 7 | release: 8 | types: 9 | - published 10 | 11 | jobs: 12 | publish: 13 | runs-on: ubuntu-24.04 14 | timeout-minutes: 30 15 | steps: 16 | - name: Checkout current branch 17 | uses: actions/checkout@v6.0.1 18 | with: 19 | fetch-depth: '0' 20 | - name: Setup Java 21 | uses: actions/setup-java@v5.1.0 22 | with: 23 | distribution: temurin 24 | java-version: 17 25 | check-latest: true 26 | - name: Publish the site 27 | run: ./sbt docs/docusaurusPublishGhpages 28 | env: 29 | GIT_DEPLOY_KEY: ${{ secrets.GIT_DEPLOY_KEY }} 30 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_match_all.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_match_all 3 | title: "Match All Query" 4 | --- 5 | 6 | The most simple query, which matches all documents, giving them all a `score` of `1.0`. 7 | 8 | To create a `MatchAll` query do the following: 9 | ```scala 10 | import zio.elasticsearch.query.MatchAllQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | 13 | val query: MatchAllQuery = matchAll 14 | ``` 15 | 16 | If you want to change the `boost`, you can use the `boost` method: 17 | ```scala 18 | val queryWithBoost: MatchAllQuery = matchAll.boost(1.2) 19 | ``` 20 | 21 | 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). 22 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_ids.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_ids 3 | title: "IDs Query" 4 | --- 5 | 6 | The `IDs` returns documents based on their IDs. This query uses document IDs stored in the _id field. 7 | 8 | In order to use the `IDs` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.IdsQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | ``` 13 | 14 | The `IDs` query can be created with `ids` method. 15 | 16 | To create a `IDs` query use the following method: 17 | ```scala 18 | val query: IdsQuery = ids("id1") 19 | val query: IdsQuery = ids("id1", "id2", "id3") 20 | ``` 21 | 22 | You can find more information about `IDs` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-ids-query.html). 23 | -------------------------------------------------------------------------------- /modules/example/src/main/scala/example/config/HttpConfig.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example.config 18 | 19 | final case class HttpConfig(port: Int) 20 | -------------------------------------------------------------------------------- /modules/example/src/main/resources/mapping.json: -------------------------------------------------------------------------------- 1 | { 2 | "settings": { 3 | "index": { 4 | "number_of_shards": 1 5 | } 6 | }, 7 | "mappings": { 8 | "_routing": { 9 | "required": true 10 | }, 11 | "properties": { 12 | "id": { 13 | "type": "keyword" 14 | }, 15 | "organization": { 16 | "type": "keyword" 17 | }, 18 | "name": { 19 | "type": "keyword" 20 | }, 21 | "url": { 22 | "type": "keyword" 23 | }, 24 | "description": { 25 | "type": "text" 26 | }, 27 | "lastCommitAt": { 28 | "type": "date" 29 | }, 30 | "stars": { 31 | "type": "integer" 32 | }, 33 | "forks": { 34 | "type": "integer" 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /modules/example/src/main/scala/example/config/ElasticsearchConfig.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example.config 18 | 19 | final case class ElasticsearchConfig(host: String, port: Int) 20 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/package.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | package object query { 20 | 21 | type GeoHash = GeoHash.Type 22 | } 23 | -------------------------------------------------------------------------------- /website/src/css/custom.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --ifm-color-primary: #2958a8; 3 | --ifm-color-primary-dark: #254f97; 4 | --ifm-color-primary-darker: #234b8f; 5 | --ifm-color-primary-darkest: #214686; 6 | --ifm-color-primary-light: #2d61b9; 7 | --ifm-color-primary-lighter: #2f65c1; 8 | --ifm-color-primary-lightest: #326acb; 9 | --ifm-code-font-size: 95% 10 | --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.1); 11 | } 12 | 13 | [data-theme='dark'] { 14 | --ifm-color-primary: #80aeff; 15 | --ifm-color-primary-dark: #5a96ff; 16 | --ifm-color-primary-darker: #4789ff; 17 | --ifm-color-primary-darkest: #337dff; 18 | --ifm-color-primary-light: #a6c6ff; 19 | --ifm-color-primary-lighter: #b9d3ff; 20 | --ifm-color-primary-lightest: #cddfff; 21 | --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3); 22 | } 23 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/GeoHash.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query 18 | 19 | import zio.prelude.Newtype 20 | 21 | object GeoHash extends Newtype[String] 22 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/executor/ElasticCredentials.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.executor 18 | 19 | final case class ElasticCredentials(username: String, password: String) 20 | -------------------------------------------------------------------------------- /modules/example/src/main/scala/example/package.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import zio.elasticsearch._ 18 | 19 | package object example { 20 | final val Index: IndexName = IndexName("repositories") 21 | final val organization: String = "zio" 22 | } 23 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/aggregation/AggregationOrder.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.aggregation 18 | 19 | import zio.elasticsearch.query.sort.SortOrder 20 | 21 | final case class AggregationOrder(value: String, order: SortOrder) 22 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/request/UpdateOutcome.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.request 18 | 19 | sealed abstract class UpdateOutcome 20 | 21 | object UpdateOutcome { 22 | case object Created extends UpdateOutcome 23 | case object Updated extends UpdateOutcome 24 | } 25 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/request/DeletionOutcome.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.request 18 | 19 | sealed abstract class DeletionOutcome 20 | 21 | object DeletionOutcome { 22 | case object Deleted extends DeletionOutcome 23 | case object NotFound extends DeletionOutcome 24 | } 25 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/request/CreationOutcome.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.request 18 | 19 | sealed abstract class CreationOutcome 20 | 21 | object CreationOutcome { 22 | case object AlreadyExists extends CreationOutcome 23 | case object Created extends CreationOutcome 24 | } 25 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/request/IsExecutable.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.request 18 | 19 | private[elasticsearch] sealed trait IsExecutable 20 | private[elasticsearch] sealed trait Executable extends IsExecutable 21 | private[elasticsearch] sealed trait NotExecutable extends IsExecutable 22 | -------------------------------------------------------------------------------- /modules/example/README.md: -------------------------------------------------------------------------------- 1 | # ZIO Elasticsearch Example Application 2 | 3 | This application represents an example of usage `zio-elasticsearch` library for **Elasticsearch 7.x**. 4 | 5 | ### Running 6 | 7 | - Run the Elasticsearch 7.x service (one can be found as part of the `docker-compose.yml` file in the root of this 8 | repository) 9 | - Start the application by running the following command: 10 | ```shell 11 | ./sbt "~example/reStart" 12 | ``` 13 | - Check whether the application is running [here](http://localhost:9000/health) 14 | - Explore endpoints using Postman collection (`zio-elasticsearch-example.postman_collection.json`) 15 | 16 | ### Description 17 | 18 | On the application startup - a **"repositories"** index will be deleted, and immediately re-created with the mapping 19 | definition given in the `resources/mapping.json` file. 20 | 21 | After successfully starting the application, you can test the exposed ZIO Elasticsearch library's API through exposed HTTP 22 | endpoints. 23 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/data/GeoPoint.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.data 18 | 19 | import zio.schema.{DeriveSchema, Schema} 20 | 21 | final case class GeoPoint(lat: Double, lon: Double) 22 | 23 | object GeoPoint { 24 | implicit val schema: Schema.CaseClass2[Double, Double, GeoPoint] = DeriveSchema.gen[GeoPoint] 25 | } 26 | -------------------------------------------------------------------------------- /modules/example/src/main/scala/example/api/ErrorResponseData.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example.api 18 | 19 | import zio.Chunk 20 | import zio.json.{DeriveJsonEncoder, JsonEncoder} 21 | 22 | final case class ErrorResponseData(body: Chunk[String]) 23 | 24 | object ErrorResponseData { 25 | implicit val encoder: JsonEncoder[ErrorResponseData] = DeriveJsonEncoder.gen[ErrorResponseData] 26 | } 27 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/ScoreMode.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query 18 | 19 | sealed trait ScoreMode 20 | 21 | object ScoreMode { 22 | case object Avg extends ScoreMode 23 | case object Max extends ScoreMode 24 | case object Min extends ScoreMode 25 | case object None extends ScoreMode 26 | case object Sum extends ScoreMode 27 | } 28 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/sort/Missing.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.sort 18 | 19 | sealed trait Missing 20 | 21 | object Missing { 22 | case object First extends Missing { 23 | override def toString: String = "_first" 24 | } 25 | 26 | case object Last extends Missing { 27 | override def toString: String = "_last" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /modules/library/src/main/scala-2/zio/elasticsearch/RoutingNewtype.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | import zio.prelude.Assertion.isEmptyString 20 | import zio.prelude.Newtype 21 | 22 | trait RoutingNewtype { 23 | object Routing extends Newtype[String] { 24 | override def assertion = assert(!isEmptyString) // scalafix:ok 25 | } 26 | type Routing = Routing.Type 27 | } 28 | -------------------------------------------------------------------------------- /modules/library/src/main/scala-3/zio/elasticsearch/RoutingNewtype.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | import zio.prelude.Assertion.isEmptyString 20 | import zio.prelude.Newtype 21 | 22 | trait RoutingNewtype { 23 | object Routing extends Newtype[String] { 24 | override inline def assertion = !isEmptyString // scalafix:ok 25 | } 26 | type Routing = Routing.Type 27 | } 28 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/sort/SortOrder.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.sort 18 | 19 | sealed trait SortOrder 20 | 21 | object SortOrder { 22 | case object Asc extends SortOrder { 23 | override def toString: String = "asc" 24 | } 25 | 26 | case object Desc extends SortOrder { 27 | override def toString: String = "desc" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /modules/library/src/test/scala/zio/elasticsearch/domain/TestDocument.scala: -------------------------------------------------------------------------------- 1 | package zio.elasticsearch.domain 2 | 3 | import zio.elasticsearch.FieldAccessorBuilder 4 | import zio.elasticsearch.data.GeoPoint 5 | import zio.schema.{DeriveSchema, Schema} 6 | 7 | import java.time.LocalDate 8 | 9 | final case class TestDocument( 10 | stringField: String, 11 | subDocumentList: List[TestSubDocument], 12 | dateField: LocalDate, 13 | intField: Int, 14 | doubleField: Double, 15 | booleanField: Boolean, 16 | geoPointField: GeoPoint, 17 | vectorField: List[Int] 18 | ) 19 | 20 | object TestDocument { 21 | implicit val schema: Schema.CaseClass8[ 22 | String, 23 | List[TestSubDocument], 24 | LocalDate, 25 | Int, 26 | Double, 27 | Boolean, 28 | GeoPoint, 29 | List[Int], 30 | TestDocument 31 | ] = DeriveSchema.gen[TestDocument] 32 | 33 | val (stringField, subDocumentList, dateField, intField, doubleField, booleanField, geoPointField, vectorField) = 34 | schema.makeAccessors(FieldAccessorBuilder) 35 | } 36 | -------------------------------------------------------------------------------- /docs/overview/requests/elastic_request_exists.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_request_exists 3 | title: "Exists Request" 4 | --- 5 | 6 | This request is used for checking whether document exists. 7 | 8 | To create a `Exists` request do the following: 9 | ```scala 10 | import zio.elasticsearch.ElasticRequest.ExistsRequest 11 | import zio.elasticsearch.ElasticRequest.exists 12 | // this import is required for using `IndexName` and `DocumentId` 13 | import zio.elasticsearch._ 14 | 15 | val request: ExistsRequest = exists(index = IndexName("index"), id = DocumentId("111")) 16 | ``` 17 | 18 | If you want to change the `routing`, you can use the `routing` method: 19 | ```scala 20 | // this import is required for `Routing` also 21 | import zio.elasticsearch._ 22 | 23 | val requestWithRouting: ExistsRequest = exists(index = IndexName("index"), id = DocumentId("111")).routing(Routing("routing")) 24 | ``` 25 | 26 | You can find more information about `Exists` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/indices-exists.html#indices-exists). 27 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/executor/response/Total.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.executor.response 18 | 19 | import zio.json.{DeriveJsonDecoder, JsonDecoder} 20 | 21 | private[elasticsearch] final case class Total(value: Long, relation: String) 22 | 23 | private[elasticsearch] object Total { 24 | implicit val decoder: JsonDecoder[Total] = DeriveJsonDecoder.gen[Total] 25 | } 26 | -------------------------------------------------------------------------------- /modules/example/src/main/scala/example/external/github/model/RepoOwner.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example.external.github.model 18 | 19 | import zio.json.{DeriveJsonDecoder, JsonDecoder, jsonField} 20 | 21 | final case class RepoOwner( 22 | @jsonField("login") 23 | organization: String 24 | ) 25 | 26 | object RepoOwner { 27 | implicit val decoder: JsonDecoder[RepoOwner] = DeriveJsonDecoder.gen[RepoOwner] 28 | } 29 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/sort/SourceType.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.sort 18 | 19 | sealed trait SourceType 20 | 21 | object SourceType { 22 | case object NumberType extends SourceType { 23 | override def toString: String = "number" 24 | } 25 | 26 | case object StringType extends SourceType { 27 | override def toString: String = "string" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /docs/overview/usage.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: overview_usage 3 | title: "Usage" 4 | --- 5 | 6 | In order to execute an Elasticsearch request we can rely on the `Elasticsearch` layer which offers an `execute` method accepting an `ElasticRequest`. In order to build the `Elasticsearch` layer we need to provide the following layers: 7 | 8 | - `ElasticExecutor`: if you provide `ElasticExecutor.local`, it will run on `localhost:9200`. Otherwise, if you want to use `ElasticExecutor.live`, you must also provide `ElasticConfig`. 9 | - `HttpClientZioBackend` 10 | 11 | ```scala 12 | import sttp.client3.httpclient.zio.HttpClientZioBackend 13 | import zio.elasticsearch._ 14 | import zio._ 15 | 16 | object ZIOElasticsearchExample extends ZIOAppDefault { 17 | val indexName = IndexName("index") 18 | val result: RIO[Elasticsearch, CreationOutcome] = 19 | Elasticsearch.execute(ElasticRequest.createIndex(indexName)) 20 | 21 | override def run = 22 | result.provide( 23 | ElasticExecutor.local, 24 | Elasticsearch.layer, 25 | HttpClientZioBackend.layer() 26 | ) 27 | } 28 | ``` 29 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/request/UpdateConflicts.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.request 18 | 19 | sealed abstract class UpdateConflicts 20 | 21 | object UpdateConflicts { 22 | case object Abort extends UpdateConflicts { 23 | override def toString: String = "abort" 24 | } 25 | 26 | case object Proceed extends UpdateConflicts { 27 | override def toString: String = "proceed" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /docs/overview/installation.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: overview_installation 3 | title: "Installation" 4 | --- 5 | 6 | To use the latest stable version of ZIO Elasticsearch, add the following line to your `build.sbt` file: 7 | 8 | ```scala mdoc:passthrough 9 | println(s"""```scala""") 10 | println(s"""libraryDependencies += "${zio.elasticsearch.BuildInfo.organization}" %% "${zio.elasticsearch.BuildInfo.name}" % "${"[^+]*".r.findFirstIn(zio.elasticsearch.BuildInfo.version).getOrElse("x.y.z")}"""") 11 | println(s"""```""") 12 | ``` 13 | 14 | However, if you want to use the latest version of the ZIO Elasticsearch library, add the following to your `build.sbt` file: 15 | 16 | ```scala mdoc:passthrough 17 | println(s"""```scala""") 18 | println(s"""resolvers += "Sonatype OSS Snapshots" at "https://s01.oss.sonatype.org/content/repositories/snapshots"""") 19 | println() 20 | println(s"""libraryDependencies += "${zio.elasticsearch.BuildInfo.organization}" %% "${zio.elasticsearch.BuildInfo.name}" % "${zio.elasticsearch.BuildInfo.version.replaceAll("\\+[0-9]{8}-[0-9]{4}", "")}"""") 21 | println(s"""```""") 22 | ``` 23 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/executor/response/InnerHitsResponse.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.executor.response 18 | 19 | import zio.json.{DeriveJsonDecoder, JsonDecoder} 20 | 21 | private[elasticsearch] final case class InnerHitsResponse(hits: Hits) 22 | 23 | private[elasticsearch] object InnerHitsResponse { 24 | implicit val decoder: JsonDecoder[InnerHitsResponse] = DeriveJsonDecoder.gen[InnerHitsResponse] 25 | } 26 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/executor/response/Shards.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.executor.response 18 | 19 | import zio.json.{DeriveJsonDecoder, JsonDecoder} 20 | 21 | private[elasticsearch] final case class Shards( 22 | total: Int, 23 | successful: Int, 24 | failed: Int 25 | ) 26 | 27 | private[elasticsearch] object Shards { 28 | implicit val decoder: JsonDecoder[Shards] = DeriveJsonDecoder.gen[Shards] 29 | } 30 | -------------------------------------------------------------------------------- /modules/example/src/main/scala/example/api/HealthCheck.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example.api 18 | 19 | import zio.http.{Method, _} 20 | import zio.json.EncoderOps 21 | import zio.json.ast.Json._ 22 | 23 | object HealthCheck { 24 | 25 | final val health: Routes[Any, Nothing] = Routes( 26 | Method.GET / Root / "health" -> handler( 27 | Response.json(Obj("name" -> Str("zio-elasticsearch-example"), "status" -> Str("up")).toJsonPretty) 28 | ) 29 | ) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/executor/response/CreateResponse.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.executor.response 18 | 19 | import zio.json.{DeriveJsonDecoder, JsonDecoder, jsonField} 20 | 21 | private[elasticsearch] final case class CreateResponse( 22 | @jsonField("_id") 23 | id: String 24 | ) 25 | 26 | private[elasticsearch] object CreateResponse { 27 | implicit val decoder: JsonDecoder[CreateResponse] = DeriveJsonDecoder.gen[CreateResponse] 28 | } 29 | -------------------------------------------------------------------------------- /modules/example/src/main/scala/example/api/package.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example 18 | 19 | import zio.http.Request 20 | 21 | package object api { 22 | implicit final class RequestOps(private val req: Request) extends AnyVal { 23 | def limit: Int = req.url.queryParams.map.get("limit").flatMap(_.headOption).flatMap(_.toIntOption).getOrElse(10) 24 | 25 | def offset: Int = req.url.queryParams.map.get("offset").flatMap(_.headOption).flatMap(_.toIntOption).getOrElse(0) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_exists.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_exists 3 | title: "Exists Query" 4 | --- 5 | 6 | The `Exists` query is used for returning documents that contain an indexed value for a field. 7 | 8 | In order to use the `Exists` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.ExistsQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | ``` 13 | 14 | You can create an `Exists` query using the `exists` method this way: 15 | ```scala 16 | val query: ExistsQuery = exists(field = "name") 17 | ``` 18 | 19 | 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: 20 | ```scala 21 | val query: ExistsQuery = exists(field = Document.name) 22 | ``` 23 | 24 | If you want to change the `boost`, you can use `boost` method: 25 | ```scala 26 | val queryWithBoost: ExistsQuery = exists(field = "name").boost(2.0) 27 | ``` 28 | 29 | 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). 30 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/executor/response/CountResponse.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.executor.response 18 | 19 | import zio.json.{DeriveJsonDecoder, JsonDecoder, jsonField} 20 | 21 | private[elasticsearch] final case class CountResponse( 22 | count: Int, 23 | @jsonField("_shards") 24 | shards: Shards 25 | ) 26 | 27 | private[elasticsearch] object CountResponse { 28 | implicit val decoder: JsonDecoder[CountResponse] = DeriveJsonDecoder.gen[CountResponse] 29 | } 30 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/executor/response/GetResponse.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.executor.response 18 | 19 | import zio.json.ast.Json 20 | import zio.json.{DeriveJsonDecoder, JsonDecoder, jsonField} 21 | 22 | private[elasticsearch] final case class GetResponse( 23 | @jsonField("_source") 24 | source: Json 25 | ) 26 | 27 | private[elasticsearch] object GetResponse { 28 | implicit val decoder: JsonDecoder[GetResponse] = DeriveJsonDecoder.gen[GetResponse] 29 | } 30 | -------------------------------------------------------------------------------- /modules/example/src/main/scala/example/api/ErrorResponse.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example.api 18 | 19 | import zio.Chunk 20 | import zio.json.{DeriveJsonEncoder, JsonEncoder} 21 | 22 | final case class ErrorResponse(errors: ErrorResponseData) 23 | 24 | object ErrorResponse { 25 | implicit val encoder: JsonEncoder[ErrorResponse] = DeriveJsonEncoder.gen[ErrorResponse] 26 | 27 | def fromReasons(reasons: String*): ErrorResponse = 28 | new ErrorResponse(ErrorResponseData(Chunk.fromIterable(reasons))) 29 | } 30 | -------------------------------------------------------------------------------- /modules/library/src/main/scala-3/zio/elasticsearch/IndexNameNewtype.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | import zio.prelude.NewtypeCustom 20 | 21 | trait IndexNameNewtype { 22 | object IndexName extends NewtypeCustom[String] { 23 | protected def validate(name: String) = 24 | IndexNameValidator.validate(name) 25 | 26 | protected inline def validateInline(inline name: String) = 27 | ${ IndexNameValidator.validateInlineImpl('name) } 28 | } 29 | type IndexName = IndexName.Type 30 | } 31 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/executor/response/BulkResponse.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.executor.response 18 | 19 | import zio.Chunk 20 | import zio.json.{DeriveJsonDecoder, JsonDecoder} 21 | 22 | final case class BulkResponse private[elasticsearch] ( 23 | took: Int, 24 | errors: Boolean, 25 | items: Chunk[BulkResponseItem] 26 | ) 27 | 28 | private[elasticsearch] object BulkResponse { 29 | implicit val decoder: JsonDecoder[BulkResponse] = DeriveJsonDecoder.gen[BulkResponse] 30 | } 31 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_match.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_match 3 | title: "Match Query" 4 | --- 5 | 6 | The `Match` query is a type of query that searches for a provided text, number, date or boolean value. 7 | This is the standard query for performing a full-text search, including options for fuzzy matching. 8 | 9 | In order to use the `Match` query import the following: 10 | 11 | ```scala 12 | import zio.elasticsearch.query.MatchQuery 13 | import zio.elasticsearch.ElasticQuery._ 14 | ``` 15 | 16 | You can create a `Match` query using the `matches` method in the following manner: 17 | ```scala 18 | val query: MatchQuery = matches(field = "message", value = "this is a test") 19 | ``` 20 | 21 | 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: 22 | ```scala 23 | val query: MatchQuery = matches(field = Document.message, value = "this is a test") 24 | ``` 25 | 26 | 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). 27 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/ElasticExecutor.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | import sttp.client4.httpclient.zio.SttpClient 20 | import zio.elasticsearch.executor.{Executor, HttpExecutor} 21 | import zio.{URLayer, ZLayer} 22 | 23 | object ElasticExecutor { 24 | lazy val live: URLayer[ElasticConfig with SttpClient, Executor] = 25 | ZLayer.fromFunction(HttpExecutor.apply _) 26 | 27 | lazy val local: URLayer[SttpClient, Executor] = 28 | ZLayer.succeed(ElasticConfig.Default) >>> live 29 | } 30 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/executor/response/Hits.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.executor.response 18 | 19 | import zio.Chunk 20 | import zio.json.{DeriveJsonDecoder, JsonDecoder, jsonField} 21 | 22 | private[elasticsearch] final case class Hits( 23 | total: Option[Total], 24 | @jsonField("max_score") 25 | maxScore: Option[Double] = None, 26 | hits: Chunk[Hit] 27 | ) 28 | 29 | private[elasticsearch] object Hits { 30 | implicit val decoder: JsonDecoder[Hits] = DeriveJsonDecoder.gen[Hits] 31 | } 32 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/executor/response/Error.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.executor.response 18 | 19 | import zio.json.{DeriveJsonDecoder, JsonDecoder, jsonField} 20 | 21 | final case class Error private[elasticsearch] ( 22 | `type`: String, 23 | reason: String, 24 | @jsonField("index_uuid") 25 | indexUuid: String, 26 | shard: String, 27 | index: String 28 | ) 29 | 30 | private[elasticsearch] object Error { 31 | implicit val decoder: JsonDecoder[Error] = DeriveJsonDecoder.gen[Error] 32 | } 33 | -------------------------------------------------------------------------------- /docs/overview/requests/elastic_request_create_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_request_create_index 3 | title: "Create Index Request" 4 | --- 5 | 6 | This request creates a new Elasticsearch index. 7 | 8 | In order to use the `CreateIndex` request import the following: 9 | ```scala 10 | import zio.elasticsearch.ElasticRequest.CreateIndexRequest 11 | import zio.elasticsearch.ElasticRequest.createIndex 12 | ``` 13 | 14 | You can create a `CreateIndex` request using the `createIndex` method in the following manner: 15 | ```scala 16 | // this import is required for using `IndexName` 17 | import zio.elasticsearch._ 18 | 19 | val request: CreateIndexRequest = createIndex(name = IndexName("index")) 20 | ``` 21 | 22 | You can also create a `CreateIndex` request using the `createIndex` method with the specific definition in the following manner: 23 | ```scala 24 | val request: CreateIndexRequest = createIndex(name = IndexName("index"), definition = """{ "mappings": { "properties": { "subDocumentList": { "type": "nested" } } } }""") 25 | ``` 26 | 27 | You can find more information about `CreateIndex` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/indices-create-index.html). 28 | -------------------------------------------------------------------------------- /modules/example/src/main/scala/example/config/AppConfig.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example.config 18 | 19 | import zio.config.magnolia.deriveConfig 20 | import zio.{Config, Layer, ZIO, ZLayer} 21 | 22 | final case class AppConfig(http: HttpConfig, elasticsearch: ElasticsearchConfig) 23 | 24 | object AppConfig { 25 | private[this] final val config = ZLayer(ZIO.config(deriveConfig[AppConfig])) 26 | 27 | lazy val live: Layer[Config.Error, ElasticsearchConfig with HttpConfig] = 28 | config.project(_.elasticsearch) ++ config.project(_.http) 29 | } 30 | -------------------------------------------------------------------------------- /modules/library/src/main/scala-3/zio/elasticsearch/IndexPatternNewtype.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | import zio.prelude.NewtypeCustom 20 | 21 | trait IndexPatternNewtype { 22 | object IndexPattern extends NewtypeCustom[String] { 23 | protected def validate(pattern: String) = 24 | IndexPatternValidator.validate(pattern) 25 | 26 | protected inline def validateInline(inline pattern: String) = 27 | ${ IndexPatternValidator.validateInlineImpl('pattern) } 28 | } 29 | type IndexPattern = IndexPattern.Type 30 | } 31 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/request/options/HasSize.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.request.options 18 | 19 | private[elasticsearch] trait HasSize[R <: HasSize[R]] { 20 | 21 | /** 22 | * Sets the maximum number of results. 23 | * 24 | * @param value 25 | * a non-negative number to set the `size` parameter in the [[zio.elasticsearch.ElasticRequest]] 26 | * @return 27 | * an instance of the [[zio.elasticsearch.ElasticRequest]] enriched with the `size` parameter. 28 | */ 29 | def size(value: Int): R 30 | } 31 | -------------------------------------------------------------------------------- /docs/overview/bulkable.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: overview_bulkable 3 | title: "Bulkable" 4 | --- 5 | 6 | If you want to use Elasticsearch's Bulk API you can do so using the `bulk` method. 7 | The `bulk` method accepts a sequence of bulkable requests which are `ElasticRequest` that inherit the `Bulkable` trait. 8 | Bulk API for Elasticsearch supports only index, create, delete, and update actions and for that reason, 9 | you can use only `Create`, `CreateOrUpdate`, `CreateWithId`, and `DeleteById` in your bulkable requests. 10 | 11 | 12 | ```scala 13 | final case class User(id: Int, name: String) 14 | 15 | object User { 16 | implicit val schema: Schema.CaseClass2[Int, String, User] = 17 | DeriveSchema.gen[User] 18 | 19 | val (id, name) = schema.makeAccessors(FieldAccessorBuilder) 20 | } 21 | 22 | val request: BulkRequest = ElasticRequest.bulk( 23 | ElasticRequest.create[User](indexName, User(1, "John Doe")), 24 | ElasticRequest.create[User](indexName, DocumentId("documentId2"), User(2, "Jane Doe")), 25 | ElasticRequest.upsert[User](indexName, DocumentId("documentId3"), User(3, "Richard Roe")), 26 | ElasticRequest.deleteById(indexName, DocumentId("documentId2")) 27 | ) 28 | 29 | Elasticsearch.execute(request) 30 | ``` 31 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/script/options/HasParams.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.script.options 18 | 19 | private[elasticsearch] trait HasParams[S <: HasParams[S]] { 20 | 21 | /** 22 | * Adds additional parameters to a script field. 23 | * 24 | * @param values 25 | * a sequence of pairs of parameter names and their values to be added to the script field 26 | * @return 27 | * an instance of the [[zio.elasticsearch.script.Script]] enriched with the `params` parameter. 28 | */ 29 | def params(values: (String, Any)*): S 30 | } 31 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_terms.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_terms 3 | title: "Terms Query" 4 | --- 5 | 6 | The `Terms` query returns documents that contain one or more exact terms in a provided field. 7 | This query is the same as the Term query, except you can search for multiple values. 8 | 9 | In order to use the `Terms` query import the following: 10 | ```scala 11 | import zio.elasticsearch.query.TermsQuery 12 | import zio.elasticsearch.ElasticQuery.terms 13 | ``` 14 | 15 | You can create a `Terms` query using the `terms` method this way: 16 | ```scala 17 | val query: TermsQuery = terms(field = "name", "a", "b", "c") 18 | ``` 19 | 20 | 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: 21 | ```scala 22 | val query: TermQuery = terms(field = Document.name, "a", "b", "c") 23 | ``` 24 | 25 | If you want to change the `boost`, you can use `boost` method: 26 | ```scala 27 | val queryWithBoost: TermsQuery = terms(field = "name", "a", "b", "c").boost(2.0) 28 | ``` 29 | 30 | You can find more information about `Terms` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-terms-query.html). 31 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/request/Document.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.request 18 | 19 | import zio.json.DecoderOps 20 | import zio.json.ast.Json 21 | import zio.json.ast.Json.Obj 22 | import zio.schema.Schema 23 | import zio.schema.codec.JsonCodec 24 | 25 | private[elasticsearch] final case class Document(json: Json) 26 | 27 | private[elasticsearch] object Document { 28 | def from[A](doc: A)(implicit schema: Schema[A]): Document = 29 | Document(JsonCodec.jsonEncoder(schema).encodeJson(doc, indent = None).fromJson[Json].fold(_ => Obj(), identity)) 30 | } 31 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/result/UpdateByQueryResult.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.result 18 | 19 | import zio.elasticsearch.executor.response.UpdateByQueryResponse 20 | 21 | final case class UpdateByQueryResult( 22 | took: Int, 23 | total: Int, 24 | updated: Int, 25 | deleted: Int, 26 | versionConflicts: Int 27 | ) 28 | 29 | object UpdateByQueryResult { 30 | def from(response: UpdateByQueryResponse): UpdateByQueryResult = 31 | UpdateByQueryResult(response.took, response.total, response.updated, response.deleted, response.versionConflicts) 32 | } 33 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/script/options/HasLang.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.script.options 18 | 19 | import zio.elasticsearch.script.ScriptLang 20 | 21 | private[elasticsearch] trait HasLang[S <: HasLang[S]] { 22 | 23 | /** 24 | * Sets the language used for analyzing the field values. 25 | * 26 | * @param value 27 | * the language used for analyzing the field values. 28 | * @return 29 | * an instance of the [[zio.elasticsearch.script.Script]] enriched with the `lang` parameter. 30 | */ 31 | def lang(value: ScriptLang): S 32 | } 33 | -------------------------------------------------------------------------------- /modules/example/src/main/scala/example/external/github/model/RepoResponse.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example.external.github.model 18 | 19 | import zio.json.{DeriveJsonDecoder, JsonDecoder, jsonField} 20 | 21 | final case class RepoResponse( 22 | id: Int, 23 | name: String, 24 | url: String, 25 | description: Option[String], 26 | @jsonField("updated_at") 27 | updatedAt: String, 28 | @jsonField("stargazers_count") 29 | stars: Int, 30 | forks: Int, 31 | owner: RepoOwner 32 | ) 33 | 34 | object RepoResponse { 35 | implicit val decoder: JsonDecoder[RepoResponse] = DeriveJsonDecoder.gen[RepoResponse] 36 | } 37 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/executor/response/UpdateByQueryResponse.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.executor.response 18 | 19 | import zio.json.{DeriveJsonDecoder, JsonDecoder, jsonField} 20 | 21 | private[elasticsearch] final case class UpdateByQueryResponse( 22 | took: Int, 23 | total: Int, 24 | updated: Int, 25 | deleted: Int, 26 | @jsonField("version_conflicts") 27 | versionConflicts: Int 28 | ) 29 | 30 | private[elasticsearch] object UpdateByQueryResponse { 31 | implicit val decoder: JsonDecoder[UpdateByQueryResponse] = DeriveJsonDecoder.gen[UpdateByQueryResponse] 32 | } 33 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/sort/options/HasFormat.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.sort.options 18 | 19 | private[elasticsearch] trait HasFormat[S <: HasFormat[S]] { 20 | 21 | /** 22 | * Sets the date format for the [[zio.elasticsearch.query.sort.SortByField]]. This method is only applicable to fields 23 | * of type `date`. 24 | * 25 | * @param value 26 | * the `date` format to set 27 | * @return 28 | * an instance of the [[zio.elasticsearch.query.sort.SortByField]] enriched with the `format` parameter. 29 | */ 30 | def format(value: String): S 31 | } 32 | -------------------------------------------------------------------------------- /website/src/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import clsx from 'clsx'; 3 | import Link from '@docusaurus/Link'; 4 | import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; 5 | import Layout from '@theme/Layout'; 6 | import HomepageFeatures from '@site/src/components/HomepageFeatures'; 7 | 8 | import styles from './index.module.css'; 9 | 10 | function HomepageHeader() { 11 | const {siteConfig} = useDocusaurusContext(); 12 | return ( 13 |
14 |
15 |

{siteConfig.title}

16 |

{siteConfig.tagline}

17 |
18 | 21 | Overview 22 | 23 |
24 |
25 |
26 | ); 27 | } 28 | 29 | export default function Home() { 30 | const {siteConfig} = useDocusaurusContext(); 31 | return ( 32 | 34 | 35 |
36 | 37 |
38 |
39 | ); 40 | } 41 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/sort/NumericType.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.sort 18 | 19 | sealed trait NumericType 20 | 21 | object NumericType { 22 | case object Double extends NumericType { 23 | override def toString: String = "double" 24 | } 25 | 26 | case object Long extends NumericType { 27 | override def toString: String = "long" 28 | } 29 | 30 | case object Date extends NumericType { 31 | override def toString: String = "date" 32 | } 33 | 34 | case object DateNanos extends NumericType { 35 | override def toString: String = "date_nanos" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/request/options/HasSearchAfter.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.request.options 18 | 19 | import zio.json.ast.Json 20 | 21 | private[elasticsearch] trait HasSearchAfter[R <: HasSearchAfter[R]] { 22 | 23 | /** 24 | * Sets the `search_after` parameter for the [[zio.elasticsearch.ElasticRequest]]. 25 | * 26 | * @param value 27 | * the JSON value to be set as the `search_after` parameter 28 | * @return 29 | * an instance of a [[zio.elasticsearch.ElasticRequest]] enriched with the `search_after` parameter. 30 | */ 31 | def searchAfter(value: Json): R 32 | } 33 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_match_phrase.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_match_phrase 3 | title: "Match Phrase Query" 4 | --- 5 | 6 | The `MatchPhrase` query analyzes the text and creates a `phrase` query out of the analyzed text. 7 | 8 | In order to use the `MatchPhrase` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.MatchPhraseQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | ``` 13 | 14 | You can create a `MatchPhrase` query using the `matchPhrase` method this way: 15 | ```scala 16 | val query: MatchPhraseQuery = matchPhrase(field = "stringField", value = "test") 17 | ``` 18 | 19 | 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: 20 | ```scala 21 | val query: MatchPhraseQuery = matchPhrase(field = Document.stringField, value = "test") 22 | ``` 23 | 24 | If you want to change the `boost`, you can use `boost` method: 25 | ```scala 26 | val queryWithBoost: MatchPhraseQuery = matchPhrase(field = Document.stringField, value = "test")g.boost(2.0) 27 | ``` 28 | 29 | 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). 30 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/sort/options/HasUnmappedType.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.sort.options 18 | 19 | private[elasticsearch] trait HasUnmappedType[S <: HasUnmappedType[S]] { 20 | 21 | /** 22 | * Sets the `unmapped type` which is used when the mapped field doesn't exist in the index. 23 | * 24 | * @param value 25 | * the type to use when the mapped field doesn't exist in the index 26 | * @return 27 | * an instance of the [[zio.elasticsearch.query.sort.SortByField]] enriched with the `unmapped type` parameter. 28 | */ 29 | def unmappedType(value: String): S 30 | } 31 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/request/options/HasRouting.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.request.options 18 | 19 | import zio.elasticsearch._ 20 | 21 | private[elasticsearch] trait HasRouting[R <: HasRouting[R]] { 22 | 23 | /** 24 | * Specifies a `routing` value to be used for this [[zio.elasticsearch.ElasticRequest]]. 25 | * 26 | * @param value 27 | * the [[Routing]] value to set for the [[zio.elasticsearch.ElasticRequest]] 28 | * @return 29 | * an instance of the [[zio.elasticsearch.ElasticRequest]] enriched with the `routing` parameter. 30 | */ 31 | def routing(value: Routing): R 32 | } 33 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/result/ElasticException.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.result 18 | 19 | class ElasticException(message: String) extends RuntimeException(message) 20 | 21 | final case class DecodingException(message: String) extends ElasticException(message) 22 | 23 | case object UnauthorizedException extends ElasticException("Wrong credentials provided.") 24 | 25 | final case class VersionConflictException(succeeded: Int, failed: Int) 26 | extends ElasticException( 27 | s"There are $failed documents failed due to version conflict, but $succeeded documents are updated successfully." 28 | ) 29 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/ElasticConfig.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | import sttp.model.Uri 20 | import zio.elasticsearch.executor.ElasticCredentials 21 | 22 | final case class ElasticConfig(host: String, port: Int, credentials: Option[ElasticCredentials], useSSL: Boolean) { 23 | lazy val uri: Uri = Uri(if (useSSL) "https" else "http", host, port) 24 | } 25 | 26 | object ElasticConfig { 27 | def apply(host: String, port: Int, useSSL: Boolean = false): ElasticConfig = ElasticConfig(host, port, None, useSSL) 28 | 29 | lazy val Default: ElasticConfig = ElasticConfig(host = "localhost", port = 9200) 30 | } 31 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/aggregation/options/HasSize.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.aggregation.options 18 | 19 | private[elasticsearch] trait HasSize[A <: HasSize[A]] { 20 | 21 | /** 22 | * Sets the maximum number of results to be returned by the aggregation. 23 | * 24 | * @param value 25 | * a non-negative number to set the `size` parameter in the 26 | * [[zio.elasticsearch.aggregation.SingleElasticAggregation]] 27 | * @return 28 | * an instance of the [[zio.elasticsearch.aggregation.SingleElasticAggregation]] enriched with the `size` parameter. 29 | */ 30 | def size(value: Int): A 31 | } 32 | -------------------------------------------------------------------------------- /docs/overview/requests/elastic_request_refresh.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_request_refresh 3 | title: "Refresh Request" 4 | --- 5 | 6 | This request is used for refreshing Elasticsearch index. 7 | 8 | In order to use the `Refresh` request import the following: 9 | ```scala 10 | import zio.elasticsearch.ElasticRequest.RefreshRequest 11 | import zio.elasticsearch.ElasticRequest.refresh 12 | // this import is required for using `IndexName`, `IndexPattern` and `MultiIndex` 13 | import zio.elasticsearch._ 14 | ``` 15 | 16 | You can create a `Refresh` request using the `refresh` method in the following manner: 17 | ```scala 18 | val request: RefreshRequest = refresh(selectors = IndexName("index")) 19 | ``` 20 | 21 | If you want to refresh more indices, you can use `refresh` method this way: 22 | ```scala 23 | val requestWithMultiIndex: RefreshRequest = refresh(selectors = MultiIndex.names(IndexName("index1"), IndexName("index2"))) 24 | ``` 25 | 26 | If you want to refresh all indices, you can use `refresh` method with `IndexPattern` this way: 27 | ```scala 28 | val requestWithIndexPattern: RefreshRequest = refresh(selectors = IndexPattern("_all")) 29 | ``` 30 | 31 | You can find more information about `Refresh` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/indices-refresh.html). 32 | 33 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/aggregation/options/WithSubAgg.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.aggregation.options 18 | 19 | import zio.elasticsearch.aggregation.SingleElasticAggregation 20 | 21 | private[elasticsearch] trait WithSubAgg[A <: WithSubAgg[A]] { 22 | 23 | /** 24 | * Adds a sub-aggregation to the aggregation. 25 | * 26 | * @param subAgg 27 | * the [[SingleElasticAggregation]] to add as sub-aggregation 28 | * @return 29 | * a new instance of the [[zio.elasticsearch.aggregation.ElasticAggregation]] with the given sub-aggregation. 30 | */ 31 | def withSubAgg(subAgg: SingleElasticAggregation): A 32 | } 33 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_match_phrase_prefix.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_match_phrase_prefix 3 | title: "Match Phrase Prefix Query" 4 | --- 5 | 6 | The `MatchPhrasePrefix` query returns documents that contain the words of a provided text, in the same order as provided. 7 | The last term of the provided text is treated as a prefix, matching any words that begin with that term. 8 | 9 | In order to use the `MatchPhrasePrefix` query import the following: 10 | ```scala 11 | import zio.elasticsearch.query.MatchPhrasePrefixQuery 12 | import zio.elasticsearch.ElasticQuery._ 13 | ``` 14 | 15 | You can create a `MatchPhrasePrefix` query using the `matchPhrasePrefix` method this way: 16 | ```scala 17 | val query: MatchPhrasePrefixQuery = matchPhrasePrefix(field = "stringField", value = "test") 18 | ``` 19 | 20 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `MatchPhrasePrefix` query using the `matchPhrasePrefix` method this way: 21 | ```scala 22 | val query: MatchPhrasePrefixQuery = matchPhrasePrefix(field = Document.stringField, value = "test") 23 | ``` 24 | 25 | You can find more information about `MatchPhrasePrefix` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-match-query-phrase-prefix.html). 26 | 27 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/request/options/HasHighlights.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.request.options 18 | 19 | import zio.elasticsearch.highlights.Highlights 20 | 21 | private[elasticsearch] trait HasHighlights[R <: HasHighlights[R]] { 22 | 23 | /** 24 | * Sets the [[zio.elasticsearch.highlights.Highlights]] for the [[zio.elasticsearch.ElasticRequest]]. 25 | * 26 | * @param value 27 | * the [[zio.elasticsearch.highlights.Highlights]] to be set 28 | * @return 29 | * an instance of the [[zio.elasticsearch.ElasticRequest]] enriched with the highlights. 30 | */ 31 | def highlights(value: Highlights): R 32 | } 33 | -------------------------------------------------------------------------------- /website/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "website", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "docusaurus": "docusaurus", 7 | "start": "docusaurus start", 8 | "build": "docusaurus build", 9 | "swizzle": "docusaurus swizzle", 10 | "deploy": "docusaurus deploy", 11 | "clear": "docusaurus clear", 12 | "serve": "docusaurus serve", 13 | "write-translations": "docusaurus write-translations", 14 | "write-heading-ids": "docusaurus write-heading-ids", 15 | "publish-gh-pages": "docusaurus deploy" 16 | }, 17 | "dependencies": { 18 | "@docusaurus/core": "^3.6.3", 19 | "@docusaurus/preset-classic": "^3.6.3", 20 | "@mdx-js/react": "^3.1.0", 21 | "clsx": "^2.1.1", 22 | "prism-react-renderer": "^2.4.1", 23 | "react": "^19.0.0", 24 | "react-dom": "^19.0.0" 25 | }, 26 | "devDependencies": { 27 | "@docusaurus/module-type-aliases": "^3.6.3", 28 | "ts-node": "^10.9.2", 29 | "typescript": "^5.7.2" 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.5%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | }, 43 | "engines": { 44 | "node": ">=16.14" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/sort/SortMode.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.sort 18 | 19 | sealed trait SortMode 20 | 21 | object SortMode { 22 | case object Avg extends SortMode { 23 | override def toString: String = "avg" 24 | } 25 | 26 | case object Max extends SortMode { 27 | override def toString: String = "max" 28 | } 29 | 30 | case object Median extends SortMode { 31 | override def toString: String = "median" 32 | } 33 | 34 | case object Min extends SortMode { 35 | override def toString: String = "min" 36 | } 37 | 38 | case object Sum extends SortMode { 39 | override def toString: String = "sum" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/aggregation/options/WithAgg.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.aggregation.options 18 | 19 | import zio.elasticsearch.aggregation.{MultipleAggregations, SingleElasticAggregation} 20 | 21 | private[elasticsearch] trait WithAgg { 22 | 23 | /** 24 | * Adds a new aggregation to the list of aggregations represented as [[MultipleAggregations]]. 25 | * 26 | * @param agg 27 | * the [[SingleElasticAggregation]] to add 28 | * @return 29 | * a new instance of [[MultipleAggregations]] with the specified aggregation added to its list of aggregations. 30 | */ 31 | def withAgg(agg: SingleElasticAggregation): MultipleAggregations 32 | } 33 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/sort/options/HasOrder.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.sort.options 18 | 19 | import zio.elasticsearch.query.sort.SortOrder 20 | 21 | private[elasticsearch] trait HasOrder[S <: HasOrder[S]] { 22 | 23 | /** 24 | * Sets the `sort order` of the field. 25 | * 26 | * @param value 27 | * the [[SortOrder]] of the field 28 | * - [[SortOrder.Asc]]: sets ascending sorting order 29 | * - [[SortOrder.Desc]]: sets descending sorting order 30 | * @return 31 | * an instance of the [[zio.elasticsearch.query.sort.Sort]] enriched with the `sort order` parameter. 32 | */ 33 | def order(value: SortOrder): S 34 | } 35 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/request/options/HasFrom.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.request.options 18 | 19 | private[elasticsearch] trait HasFrom[R <: HasFrom[R]] { 20 | 21 | /** 22 | * Sets the starting offset from where the [[zio.elasticsearch.ElasticRequest.SearchRequest]] or the 23 | * [[zio.elasticsearch.ElasticRequest.SearchAndAggregateRequest]] return results. 24 | * 25 | * @param value 26 | * a non-negative number to set the `from` parameter in the [[zio.elasticsearch.ElasticRequest]] 27 | * @return 28 | * an instance of the [[zio.elasticsearch.ElasticRequest]] enriched with the `from` parameter. 29 | */ 30 | def from(value: Int): R 31 | } 32 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_boosting.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_boosting 3 | title: "Boosting Query" 4 | --- 5 | 6 | The `Boosting` query returns documents that match the query marked as `positive` while reducing the relevance score of documents that also match a query which is marked as `negative` query. 7 | 8 | In order to use the `Boosting` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.BoostingQuery 11 | import zio.elasticsearch.ElasticQuery.boostingQuery 12 | ``` 13 | 14 | You can create a `Boosting` query using the `boosting` method this way: 15 | ```scala 16 | val query: BoostingQuery = boosting(negativeBoost = 0.5f, negativeQuery = contains(field = "testField", value = "a"), positiveQuery = startsWith(field = "testId", value = "b")) 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Boosting` query using the `boosting` method this way: 20 | ```scala 21 | val query: BoostingQuery = boosting(negativeBoost = 0.5f, negativeQuery = contains(field = Document.stringField, value = "a"), positiveQuery = startsWith(field = Document.id, value = "b")) 22 | ``` 23 | 24 | You can find more information about `Boosting` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html#boosting-query-ex-request). 25 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/sort/options/HasMissing.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.sort.options 18 | 19 | import zio.elasticsearch.query.sort.Missing 20 | 21 | private[elasticsearch] trait HasMissing[S <: HasMissing[S]] { 22 | 23 | /** 24 | * Sets the value to use when a document is missing a value for the field being sorted. 25 | * 26 | * @param value 27 | * the `missing` value behaviour 28 | * - [[Missing.First]]: treated as first 29 | * - [[Missing.Last]]: treated as last 30 | * @return 31 | * an instance of the [[zio.elasticsearch.query.sort.SortByField]] enriched with the `missing` parameter. 32 | */ 33 | def missing(value: Missing): S 34 | } 35 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/aggregation/options/HasMissing.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.aggregation.options 18 | 19 | private[elasticsearch] trait HasMissing[A <: HasMissing[A]] { 20 | 21 | /** 22 | * Sets the `missing` parameter for the [[zio.elasticsearch.aggregation.ElasticAggregation]]. The`missing` parameter 23 | * provides a value to use when a document is missing the field that the aggregation is running on. 24 | * 25 | * @param value 26 | * the value to use for missing documents 27 | * @return 28 | * an instance of the [[zio.elasticsearch.aggregation.ElasticAggregation]] enriched with the `missing` parameter. 29 | */ 30 | def missing(value: Double): A 31 | } 32 | -------------------------------------------------------------------------------- /docs/overview/aggregations/elastic_aggregation_bucket_selector.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_aggregation_bucket_selector 3 | title: "Bucket Selector Aggregation" 4 | --- 5 | 6 | This aggregation is a parent pipeline aggregation which executes a script which determines whether the current bucket will be retained in the parent multi-bucket aggregation. 7 | 8 | To create a `BucketSelector` aggregation do the following: 9 | ```scala 10 | import zio.elasticsearch.aggregation.BucketSelectorAggregation 11 | import zio.elasticsearch.ElasticAggregation.bucketSelectorAggregation 12 | import zio.elasticsearch.script.Script 13 | 14 | val aggregation: BucketSelectorAggregation = bucketSelectorAggregation(name = "aggregationSelector", script = Script("params.value > 10"), bucketsPath = Map("value" -> "otherAggregation")) 15 | ``` 16 | 17 | If you want to add aggregation (on the same level), you can use `withAgg` method: 18 | ```scala 19 | val multipleAggregations: MultipleAggregations = bucketSelectorAggregation(name = "aggregationSelector", script = Script("params.value > 10"), bucketsPath = Map("value" -> "otherAggregation")).withAgg(maxAggregation(name = "maxAggregation", field = Document.doubleField)) 20 | ``` 21 | 22 | You can find more information about `BucketSelector` aggregation [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations-pipeline-bucket-selector-aggregation.html). 23 | -------------------------------------------------------------------------------- /docs/overview/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: overview_index 3 | title: "Summary" 4 | --- 5 | 6 | # ZIO Elasticsearch 7 | 8 | ![scala-version][scala-version-badge] 9 | [![CI](https://github.com/lambdaworks/zio-elasticsearch/actions/workflows/ci.yml/badge.svg)](https://github.com/lambdaworks/zio-elasticsearch/actions/workflows/ci.yml) 10 | [![Sonatype Releases](https://img.shields.io/nexus/r/https/s01.oss.sonatype.org/io.lambdaworks/zio-elasticsearch_2.13.svg?label=Sonatype%20Release)](https://s01.oss.sonatype.org/content/repositories/releases/io/lambdaworks/zio-elasticsearch_2.13/) 11 | [![Sonatype Snapshots](https://img.shields.io/nexus/s/https/s01.oss.sonatype.org/io.lambdaworks/zio-elasticsearch_2.13.svg?label=Sonatype%20Snapshot)](https://s01.oss.sonatype.org/content/repositories/snapshots/io/lambdaworks/zio-elasticsearch_2.13/) 12 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 13 | 14 | [scala-version-badge]: https://img.shields.io/badge/scala-2.13.10-blue?logo=scala&color=red 15 | 16 | ZIO Elasticsearch is a type-safe and streaming-friendly ZIO native Elasticsearch client. 17 | 18 | The library depends on sttp as an HTTP client for executing requests, and other ZIO libraries such as ZIO Schema and ZIO Prelude. 19 | 20 | The following versions are supported: 21 | - Scala: 2.12, 2.13 and 3 22 | - ZIO: 2 23 | - Elasticsearch: 7, 8 24 | - JVM 11+ 25 | -------------------------------------------------------------------------------- /website/src/components/HomepageFeatures/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import clsx from 'clsx'; 3 | import styles from './styles.module.css'; 4 | 5 | const FeatureList = [ 6 | { 7 | title: 'Type-safe', 8 | description: ( 9 | <> 10 | Utilizes Scala's type system to catch bugs at compile time 11 | 12 | ), 13 | }, 14 | { 15 | title: 'Streaming-friendly', 16 | description: ( 17 | <> 18 | Naturally integrates with ZIO's feature-rich ZStreams 19 | 20 | ), 21 | }, 22 | { 23 | title: 'ZIO-native', 24 | description: ( 25 | <> 26 | Built using ZIO and libraries within it's ecosystem, with ZIO in mind 27 | 28 | ), 29 | }, 30 | ]; 31 | 32 | function Feature({title, description}) { 33 | return ( 34 |
35 |
36 |

{title}

37 |

{description}

38 |
39 |
40 | ); 41 | } 42 | 43 | export default function HomepageFeatures() { 44 | return ( 45 |
46 |
47 |
48 | {FeatureList.map((props, idx) => ( 49 | 50 | ))} 51 |
52 |
53 |
54 | ); 55 | } 56 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/executor/response/Hit.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.executor.response 18 | 19 | import zio.json.ast.Json 20 | import zio.json.ast.Json.Obj 21 | import zio.json.{DeriveJsonDecoder, JsonDecoder, jsonField} 22 | 23 | private[elasticsearch] final case class Hit( 24 | @jsonField("_index") 25 | index: String, 26 | @jsonField("_id") 27 | id: String, 28 | @jsonField("_score") 29 | score: Option[Double] = None, 30 | @jsonField("_source") 31 | source: Json, 32 | @jsonField("inner_hits") 33 | innerHits: Option[Obj], 34 | sort: Option[Json], 35 | highlight: Option[Json] 36 | ) 37 | 38 | private[elasticsearch] object Hit { 39 | implicit val decoder: JsonDecoder[Hit] = DeriveJsonDecoder.gen[Hit] 40 | } 41 | -------------------------------------------------------------------------------- /modules/library/src/main/scala-2/zio/elasticsearch/IndexNameValidation.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | import org.apache.commons.lang3.StringUtils 20 | import org.apache.commons.lang3.StringUtils.{equalsAny, startsWithAny} 21 | import zio.Chunk 22 | 23 | object IndexNameValidation { 24 | def isValid(name: String): Boolean = { 25 | def containsAny(string: String, params: Chunk[String]): Boolean = 26 | params.exists(StringUtils.contains(string, _)) 27 | 28 | name.toLowerCase == name && 29 | name.nonEmpty && 30 | !startsWithAny(name, "+", "-", "_") && 31 | !containsAny(string = name, params = Chunk("*", "?", "\"", "<", ">", "|", " ", ",", "#", ":")) && 32 | !equalsAny(name, ".", "..") && 33 | name.getBytes().length <= 255 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/StreamConfig.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | final case class StreamConfig(searchAfter: Boolean, keepAlive: String, pageSize: Option[Int] = None) { self => 20 | 21 | def keepAliveFor(s: String): StreamConfig = self.copy(keepAlive = s) 22 | 23 | def withPageSize(n: Int): StreamConfig = self.copy(pageSize = Some(n)) 24 | } 25 | 26 | object StreamConfig { 27 | lazy val Default: StreamConfig = StreamConfig(searchAfter = false, keepAlive = DefaultKeepAlive) 28 | lazy val Scroll: StreamConfig = StreamConfig(searchAfter = false, keepAlive = DefaultKeepAlive) 29 | lazy val SearchAfter: StreamConfig = StreamConfig(searchAfter = true, keepAlive = DefaultKeepAlive) 30 | 31 | private val DefaultKeepAlive = "1m" 32 | } 33 | -------------------------------------------------------------------------------- /modules/library/src/main/scala-2/zio/elasticsearch/IndexPatternValidation.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | import org.apache.commons.lang3.StringUtils 20 | import org.apache.commons.lang3.StringUtils.{equalsAny, startsWithAny} 21 | import zio.Chunk 22 | 23 | object IndexPatternValidation { 24 | def isValid(pattern: String): Boolean = { 25 | def containsAny(string: String, params: Chunk[String]): Boolean = 26 | params.exists(StringUtils.contains(string, _)) 27 | 28 | pattern.toLowerCase == pattern && 29 | pattern.nonEmpty && 30 | !startsWithAny(pattern, "+") && 31 | !containsAny(string = pattern, params = Chunk("?", "\"", "<", ">", "|", " ", ",", "#", ":")) && 32 | !equalsAny(pattern, ".", "..") && 33 | pattern.getBytes().length <= 255 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/options/HasBoost.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.options 18 | 19 | private[elasticsearch] trait HasBoost[Q <: HasBoost[Q]] { 20 | 21 | /** 22 | * Sets the `boost` parameter for this [[zio.elasticsearch.query.ElasticQuery]]. The `boost` value is a positive 23 | * multiplier applied to the score of documents matching the query. A value greater than 1 increases the relevance 24 | * score of matching documents, while a value less than 1 decreases it. The default `boost` value is 1. 25 | * 26 | * @param value 27 | * a non-negative real number to set `boost` parameter to 28 | * @return 29 | * a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the `boost` value set. 30 | */ 31 | def boost(value: Double): Q 32 | } 33 | -------------------------------------------------------------------------------- /modules/library/src/test/scala/zio/elasticsearch/ElasticPrimitiveSpec.scala: -------------------------------------------------------------------------------- 1 | package zio.elasticsearch 2 | 3 | import zio.elasticsearch.ElasticQuery._ 4 | import zio.elasticsearch.query.Match 5 | import zio.test.Assertion.equalTo 6 | import zio.test._ 7 | 8 | import java.util.UUID 9 | 10 | object ElasticPrimitiveSpec extends ZIOSpecDefault { 11 | override def spec: Spec[TestEnvironment, Any] = 12 | suite("ElasticPrimitive")( 13 | test("BigDecimal") { 14 | assert(matches(FieldName, BigDecimal(1)))( 15 | equalTo(Match[Any, BigDecimal](FieldName, BigDecimal(1))) 16 | ) 17 | }, 18 | test("Boolean") { 19 | assert(matches(FieldName, true))(equalTo(Match[Any, Boolean](FieldName, true))) 20 | }, 21 | test("Double") { 22 | assert(matches(FieldName, 1.00))(equalTo(Match[Any, Double](FieldName, 1.00))) 23 | }, 24 | test("Int") { 25 | assert(matches(FieldName, 1))(equalTo(Match[Any, Int](FieldName, 1))) 26 | }, 27 | test("Long") { 28 | assert(matches(FieldName, 1L))(equalTo(Match[Any, Long](FieldName, 1L))) 29 | }, 30 | test("String") { 31 | assert(matches(FieldName, "string"))(equalTo(Match[Any, String](FieldName, "string"))) 32 | }, 33 | test("UUID") { 34 | val uuid = UUID.randomUUID() 35 | assert(matches(FieldName, uuid))(equalTo(Match[Any, UUID](FieldName, uuid))) 36 | } 37 | ) 38 | 39 | private val FieldName = "fieldName" 40 | } 41 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_prefix.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_prefix 3 | title: "Prefix Query" 4 | --- 5 | 6 | The `Prefix` query returns documents that contain a specific prefix in a provided field. 7 | 8 | In order to use the `Prefix` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.PrefixQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | ``` 13 | 14 | You can create a `Prefix` query using the `prefix` method this way: 15 | ```scala 16 | val query: PrefixQuery = prefix(field = Document.name, value = "test") 17 | ``` 18 | 19 | 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: 20 | ```scala 21 | val query: PrefixQuery = prefix(field = Document.name, value = "test") 22 | ``` 23 | 24 | If you want to change the `case_insensitive`, you can use `caseInsensitive`, `caseInsensitiveFalse` or `caseInsensitiveTrue` method: 25 | ```scala 26 | val queryWithCaseInsensitive: PrefixQuery = prefix(field = Document.name, value = "test").caseInsensitive(true) 27 | val queryWithCaseInsensitiveFalse: PrefixQuery = prefix(field = Document.name, value = "test").caseInsensitiveFalse 28 | val queryWithCaseInsensitiveTrue: PrefixQuery = prefix(field = Document.name, value = "test").caseInsensitiveTrue 29 | ``` 30 | 31 | You can find more information about `Prefix` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-prefix-query.html). 32 | -------------------------------------------------------------------------------- /docs/overview/requests/elastic_request_count.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_request_count 3 | title: "Count Request" 4 | --- 5 | 6 | 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. 7 | 8 | In order to use the `Count` request import the following: 9 | ```scala 10 | import zio.elasticsearch.ElasticRequest.CountRequest 11 | import zio.elasticsearch.ElasticRequest.count 12 | ``` 13 | 14 | You can create a `Count` request using the `count` method without specifying query this way: 15 | ```scala 16 | // this import is required for using `IndexName` 17 | import zio.elasticsearch._ 18 | 19 | val request: CountRequest = count(index = IndexName("index")) 20 | ``` 21 | 22 | You can create a `Count` request using the `count` method with specified query this way: 23 | ```scala 24 | import zio.elasticsearch.ElasticQuery._ 25 | 26 | val request: CountRequest = count(index = IndexName("index"), query = contains(field = Document.name, value = "test")) 27 | ``` 28 | 29 | If you want to change the `routing`, you can use the `routing` method: 30 | ```scala 31 | // this import is required for using `Routing` also 32 | import zio.elasticsearch._ 33 | 34 | val requestWithRouting: CountRequest = count(index = Index("index")).routing(Routing("routing")) 35 | ``` 36 | 37 | You can find more information about `Count` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-count.html). 38 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_regexp.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_regexp 3 | title: "Regexp Query" 4 | --- 5 | 6 | The `Regexp` query returns documents that contain terms matching a regular expression. 7 | 8 | In order to use the `Regexp` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.RegexpQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | ``` 13 | 14 | You can create a `Regexp` query using the `regexp` method this way: 15 | ```scala 16 | val query: RegexpQuery = regexp(field = "name", value = "t.*st") 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Regexp` query using the `regexp` method this way: 20 | ```scala 21 | val query: RegexpQuery = regexp(field = Document.name, value = "t.*st") 22 | ``` 23 | 24 | If you want to change the `case_insensitive`, you can use `caseInsensitive`, `caseInsensitiveFalse` or `caseInsensitiveTrue` method: 25 | ```scala 26 | val queryWithCaseInsensitive: RegexpQuery = regexp(field = Document.name, value = "t.*st").caseInsensitive(true) 27 | val queryWithCaseInsensitiveFalse: RegexpQuery = regexp(field = Document.name, value = "t.*st").caseInsensitiveFalse 28 | val queryWithCaseInsensitiveTrue: RegexpQuery = regexp(field = Document.name, value = "t.*st").caseInsensitiveTrue 29 | ``` 30 | 31 | You can find more information about `Regexp` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-regexp-query.html). 32 | 33 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/request/options/HasSort.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.request.options 18 | 19 | import zio.elasticsearch.query.sort.Sort 20 | 21 | private[elasticsearch] trait HasSort[R <: HasSort[R]] { 22 | 23 | /** 24 | * Sets the sorting criteria for the [[zio.elasticsearch.ElasticRequest.SearchRequest]] or the 25 | * [[zio.elasticsearch.ElasticRequest.SearchAndAggregateRequest]]. 26 | * 27 | * @param sort 28 | * required [[zio.elasticsearch.query.sort.Sort]] object that define the sorting criteria 29 | * @param sorts 30 | * rest of the [[zio.elasticsearch.query.sort.Sort]] objects that define the sorting criteria 31 | * @return 32 | * an instance of the [[zio.elasticsearch.ElasticRequest]] enriched with the sorting criteria. 33 | */ 34 | def sort(sort: Sort, sorts: Sort*): R 35 | } 36 | -------------------------------------------------------------------------------- /docs/overview/requests/elastic_request_aggregate.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_request_aggregate 3 | title: "Aggregation Request" 4 | --- 5 | 6 | This request is used to create aggregations which summarizes your data as metrics, statistics, or other analytics. 7 | 8 | To create a `Aggregate` request do the following: 9 | ```scala 10 | import zio.elasticsearch.ElasticRequest.AggregateRequest 11 | import zio.elasticsearch.ElasticRequest.aggregate 12 | // this import is required for using `IndexName`, `IndexPattern` and `MultiIndex` 13 | import zio.elasticsearch._ 14 | import zio.elasticsearch.ElasticAggregation._ 15 | 16 | val request: AggregateRequest = aggregate(selectors = IndexName("index"), aggregation = maxAggregation(name = "aggregation", field = "intField")) 17 | ``` 18 | 19 | If you want to create `Aggregate` request with `IndexPattern`, do the following: 20 | ```scala 21 | val requestWithIndexPattern: AggregateRequest = aggregate(selectors = IndexPattern("index*"), aggregation = maxAggregation(name = "aggregation", field = "intField")) 22 | ``` 23 | 24 | If you want to create `Aggregate` request with `MultiIndex`, do the following: 25 | ```scala 26 | val requestWithMultiIndex: AggregateRequest = aggregate(selectors = MultiIndex.names(IndexName("index1"), IndexName("index2")), aggregation = maxAggregation(name = "aggregation", field = "intField")) 27 | ``` 28 | 29 | You can find more information about `Aggregate` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations.html). 30 | -------------------------------------------------------------------------------- /docs/about/contributing.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: about_contributing 3 | title: "Contributing" 4 | --- 5 | 6 | We welcome contributions from anybody wishing to participate. All code or documentation that is provided must be licensed under [Apache 2.0](https://github.com/lambdaworks/zio-elasticsearch/blob/main/LICENSE). 7 | 8 | ## General Workflow 9 | 10 | 1. Make sure you can license your work under Apache 2.0. 11 | 12 | 2. Before starting work, make sure there is a ticket on the issue, and if not, make sure to create one. It can help accelerate the acceptance process if the change is agreed upon. 13 | 14 | 3. If you don't have write access to the repository, you should do your work on a local branch of your own fork. If you do have write access to the repository, you should avoid working directly on the main branch. 15 | 16 | 4. When your work is completed, verify it with following commands: 17 | 18 | ```shell 19 | sbt check 20 | sbt +test 21 | ``` 22 | 23 | 5. Submit a Pull Request. 24 | 25 | 6. Anyone can comment on a Pull Request, and you are expected to answer questions or to incorporate feedback. 26 | 27 | ## General Guidelines 28 | 29 | - We recommend for the work to be accompanied by unit tests. 30 | 31 | - The commit messages should be clear and short, and if more details are needed, specify a body. 32 | 33 | - Follow the structure of the code in this repository, and the formatting rules used. You can format your code properly with the following command: 34 | 35 | ```shell 36 | sbt prepare 37 | ``` -------------------------------------------------------------------------------- /modules/example/src/main/scala/example/external/github/RepoFetcher.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example.external.github 18 | 19 | import example.GitHubRepo 20 | import example.external.github.model.RepoResponse 21 | import sttp.client4.httpclient.zio.SttpClient 22 | import sttp.client4.{UriContext, basicRequest} 23 | import zio.json.DecoderOps 24 | import zio.{Chunk, RIO, ZIO} 25 | 26 | object RepoFetcher { 27 | 28 | def fetchAllByOrganization(organization: String, limit: Int = 100): RIO[SttpClient, Chunk[GitHubRepo]] = 29 | for { 30 | client <- ZIO.service[SttpClient] 31 | req = basicRequest.get(uri"https://api.github.com/orgs/$organization/repos?per_page=$limit") 32 | res <- client.send(req) 33 | } yield res.body.toOption 34 | .map(_.fromJson[Chunk[RepoResponse]].fold(_ => Chunk.empty, _.map(GitHubRepo.fromResponse))) 35 | .getOrElse(Chunk.empty) 36 | } 37 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/options/HasMinimumShouldMatch.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.options 18 | 19 | private[elasticsearch] trait HasMinimumShouldMatch[Q <: HasMinimumShouldMatch[Q]] { 20 | 21 | /** 22 | * Sets the `minimumShouldMatch` parameter for this [[zio.elasticsearch.ElasticQuery]]. The `minimumShouldMatch` value 23 | * is the number of should clauses returned documents must match. If the [[zio.elasticsearch.query.BoolQuery]] 24 | * includes at least one `should` clause and no `must`/`filter` clauses, the default value is 1. Otherwise, the 25 | * default value is 0. 26 | * 27 | * @param value 28 | * a number to set `minimumShouldMatch` parameter to 29 | * @return 30 | * a new instance of the [[zio.elasticsearch.ElasticQuery]] with the `minimumShouldMatch` value set. 31 | */ 32 | def minimumShouldMatch(value: Int): Q 33 | } 34 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_match_boolean_prefix.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_match_boolean_prefix 3 | title: "Match Boolean Prefix Query" 4 | --- 5 | 6 | The `MatchBooleanPrefix` query analyzes its input and constructs a `bool` query from the terms. Each term except the last is used in a `term` query. 7 | The last term is used in a `prefix` query. 8 | 9 | In order to use the `MatchBooleanPrefix` query import the following: 10 | ```scala 11 | import zio.elasticsearch.query.MatchBooleanPrefixQuery 12 | import zio.elasticsearch.ElasticQuery._ 13 | ``` 14 | 15 | You can create a `MatchBooleanPrefix` query using the `matchBooleanPrefix` method this way: 16 | ```scala 17 | val query: MatchBooleanPrefixQuery = matchBooleanPrefix(field = "stringField", value = "test") 18 | ``` 19 | 20 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `MatchBooleanPrefix` query using the `matchBooleanPrefix` method this way: 21 | ```scala 22 | val query: MatchBooleanPrefixQuery = matchBooleanPrefix(field = Document.stringField, value = "test") 23 | ``` 24 | 25 | If you want to change the `minimum_should_match` parameter, you can use the `minimumShouldMatch` method: 26 | ```scala 27 | val queryWithMinimumShouldMatch: MatchBooleanPrefixQuery = matchBooleanPrefix(field = Document.stringField, value = "test").minimumShouldMatch(2) 28 | ``` 29 | 30 | You can find more information about `MatchBooleanPrefix` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-match-bool-prefix-query.html). 31 | 32 | -------------------------------------------------------------------------------- /docs/overview/requests/elastic_request_get_by_id.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_request_get_by_id 3 | title: "Get By ID Request" 4 | --- 5 | 6 | The `GetById` request retrieves the specified JSON document from an Elasticsearch index. 7 | 8 | To create a `GetById` request do the following: 9 | ```scala 10 | import zio.elasticsearch.ElasticRequest.GetByIdRequest 11 | import zio.elasticsearch.ElasticRequest.getById 12 | // this import is required for using `IndexName` and `DocumentId` 13 | import zio.elasticsearch._ 14 | 15 | val request: GetByIdRequest = getById(index = IndexName("index"), id = DocumentId("111")) 16 | ``` 17 | 18 | If you want to change the `refresh`, you can use `refresh`, `refreshFalse` or `refreshTrue` method: 19 | ```scala 20 | val requestWithRefresh: GetByIdRequest = getById(index = IndexName("index"), id = DocumentId("111")).refresh(true) 21 | val requestWithRefreshFalse: GetByIdRequest = getById(index = IndexName("index"), id = DocumentId("111")).refreshFalse 22 | val requestWithRefreshTrue: GetByIdRequest = getById(index = IndexName("index"), id = DocumentId("111")).refreshTrue 23 | ``` 24 | 25 | If you want to change the `routing`, you can use the `routing` method: 26 | ```scala 27 | // this import is required for `Routing` also 28 | import zio.elasticsearch._ 29 | 30 | val requestWithRouting: GetByIdRequest = getById(index = IndexName("index"), id = DocumentId("111")).routing(Routing("routing")) 31 | ``` 32 | 33 | You can find more information about `GetById` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/docs-get.html). 34 | 35 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/MultiMatchType.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query 18 | 19 | sealed trait MultiMatchType 20 | 21 | object MultiMatchType { 22 | case object BestFields extends MultiMatchType { 23 | override def toString: String = "best_fields" 24 | } 25 | 26 | case object BoolPrefix extends MultiMatchType { 27 | override def toString: String = "bool_prefix" 28 | } 29 | 30 | case object CrossFields extends MultiMatchType { 31 | override def toString: String = "cross_fields" 32 | } 33 | 34 | case object MostFields extends MultiMatchType { 35 | override def toString: String = "most_fields" 36 | } 37 | 38 | case object Phrase extends MultiMatchType { 39 | override def toString: String = "phrase_fields" 40 | } 41 | 42 | case object PhrasePrefix extends MultiMatchType { 43 | override def toString: String = "phrase_prefix" 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /docs/overview/requests/elastic_request_delete_by_id.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_request_delete_by_id 3 | title: "Delete By ID Request" 4 | --- 5 | 6 | This query removes a JSON document from the specified index. 7 | 8 | To create a `DeleteById` request do the following: 9 | ```scala 10 | import zio.elasticsearch.ElasticRequest.DeleteByIdRequest 11 | import zio.elasticsearch.ElasticRequest.deleteById 12 | // this import is required for using `IndexName` and `DocumentId` 13 | import zio.elasticsearch._ 14 | 15 | val request: DeleteByIdRequest = deleteById(index = IndexName("index"), id = DocumentId("111")) 16 | ``` 17 | 18 | If you want to change the `refresh`, you can use `refresh`, `refreshFalse` or `refreshTrue` method: 19 | ```scala 20 | val requestWithRefresh: DeleteByIdRequest = deleteById(index = IndexName("index"), id = DocumentId("111")).refresh(true) 21 | val requestWithRefreshFalse: DeleteByIdRequest = deleteById(index = IndexName("index"), id = DocumentId("111")).refreshFalse 22 | val requestWithRefreshTrue: DeleteByIdRequest = deleteById(index = IndexName("index"), id = DocumentId("111")).refreshTrue 23 | ``` 24 | 25 | If you want to change the `routing`, you can use the `routing` method: 26 | ```scala 27 | // this import is required for `Routing` also 28 | import zio.elasticsearch._ 29 | 30 | val requestWithRouting: DeleteByIdRequest = deleteById(index = IndexName("index"), id = DocumentId("111")).routing(Routing("routing")) 31 | ``` 32 | 33 | You can find more information about `DeleteById` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/docs-delete.html). 34 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_constant_score.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_constant_score 3 | title: "Constant Score Query" 4 | --- 5 | 6 | The `ConstantScore` query wraps a filter query and returns every matching document with a relevance score equal to the boost parameter value. 7 | 8 | In order to use the `ConstantScore` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.ConstantScoreQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | ``` 13 | 14 | You can create a `ConstantScore` query with arbitrary query(`MatchPhrase` in this example) using the `constantScore` method in the following manner: 15 | ```scala 16 | val query: ConstantScoreQuery = constantScore(matchPhrase(field = "name", value = "test")) 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `ConstantScore` query with arbitrary [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) query(`MatchPhrase` in this example) using the `constantScore` method in the following manner: 20 | ```scala 21 | val query: ConstantScoreQuery = constantScore(matchPhrase(field = Document.name, value = "test")) 22 | ``` 23 | 24 | If you want to change the `boost`, you can use `boost` method: 25 | ```scala 26 | val queryWithBoost: ConstantScoreQuery = constantScore(matchPhrase(field = Document.name, value = "test")).boost(2.2) 27 | ``` 28 | 29 | You can find more information about `ConstantScore` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-constant-score-query.html). 30 | 31 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/options/HasInnerHits.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.options 18 | 19 | import zio.elasticsearch.query.InnerHits 20 | 21 | private[elasticsearch] trait HasInnerHits[Q <: HasInnerHits[Q]] { 22 | 23 | /** 24 | * Sets the inner hits for this [[zio.elasticsearch.query.ElasticQuery]] to the default `InnerHits()` value. 25 | * 26 | * @return 27 | * a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the default inner hits. 28 | */ 29 | final def innerHits: Q = innerHits(InnerHits()) 30 | 31 | /** 32 | * Sets the inner hits configuration for the [[zio.elasticsearch.query.NestedQuery]]. 33 | * 34 | * @param innerHits 35 | * the configuration for inner hits 36 | * @return 37 | * a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the specified inner hits configuration. 38 | */ 39 | def innerHits(innerHits: InnerHits): Q 40 | } 41 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_term.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_term 3 | title: "Term Query" 4 | --- 5 | 6 | The `Term` query returns documents that contain an exact term in the provided field. 7 | 8 | In order to use the `Term` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.TermQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | ``` 13 | 14 | You can create a `Term` query using the `term` method this way: 15 | ```scala 16 | val query: TermQuery = term(field = "stringField", value = "test") 17 | ``` 18 | 19 | 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: 20 | ```scala 21 | val query: TermQuery = term(field = Document.name, value = "test") 22 | ``` 23 | 24 | If you want to change the `boost`, you can use `boost` method: 25 | ```scala 26 | val queryWithBoost: TermQuery = term(field = Document.name, value = "test").boost(2.0) 27 | ``` 28 | 29 | If you want to change the `case_insensitive`, you can use `caseInsensitive`, `caseInsensitiveFalse` or `caseInsensitiveTrue` method: 30 | ```scala 31 | val queryWithCaseInsensitive: TermQuery = term(field = Document.name, value = "test").caseInsensitive(true) 32 | val queryWithCaseInsensitiveFalse: TermQuery = term(field = Document.name, value = "test").caseInsensitiveFalse 33 | val queryWithCaseInsensitiveTrue: TermQuery = term(field = Document.name, value = "test").caseInsensitiveTrue 34 | ``` 35 | 36 | You can find more information about `Term` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-term-query.html). 37 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/sort/options/HasNumericType.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.sort.options 18 | 19 | import zio.elasticsearch.query.sort.NumericType 20 | 21 | private[elasticsearch] trait HasNumericType[S <: HasNumericType[S]] { 22 | 23 | /** 24 | * Sets the `numeric type` that should be used for sorting the field. With `numeric type` it is possible to cast the 25 | * values from one type to another. 26 | * 27 | * @param value 28 | * the [[NumericType]] that should be used for sorting the field 29 | * - [[NumericType.Date]]: converts values to Date 30 | * - [[NumericType.DateNanos]]: converts values to DateNanos 31 | * - [[NumericType.Double]]: converts values to Double 32 | * - [[NumericType.Long]]: converts values to Long 33 | * @return 34 | * an instance of the [[zio.elasticsearch.query.sort.SortByField]] enriched with the `numeric type` parameter. 35 | */ 36 | def numericType(value: NumericType): S 37 | } 38 | -------------------------------------------------------------------------------- /docs/overview/aggregations/elastic_aggregation_missing.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_aggregation_missing 3 | title: "Missing Aggregation" 4 | --- 5 | 6 | The `Missing` aggregation is a field data based single bucket aggregation, that creates a bucket of all documents in the current document set context that are missing a field value. 7 | 8 | In order to use the `Missing` aggregation import the following: 9 | ```scala 10 | import zio.elasticsearch.aggregation.MissingAggregation 11 | import zio.elasticsearch.ElasticAggregation.missingAggregation 12 | ``` 13 | 14 | You can create a `Missing` aggregation using the `missingAggregation` method this way: 15 | ```scala 16 | val aggregation: MissingAggregation = missingAggregation(name = "missingAggregation", field = "stringField") 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Missing` aggregation using the `missingAggregation` method this way: 20 | ```scala 21 | // Document.stringField must be string value, because of Missing aggregation 22 | val aggregation: MissingAggregation = missingAggregation(name = "missingAggregation", field = Document.stringField) 23 | ``` 24 | 25 | If you want to add aggregation (on the same level), you can use `withAgg` method: 26 | ```scala 27 | val multipleAggregations: MultipleAggregations = missingAggregation(name = "missingAggregation1", field = Document.stringField).withAgg(missingAggregation(name = "missingAggregation2", field = Document.stringField)) 28 | ``` 29 | 30 | You can find more information about `Missing` aggregation [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations-bucket-missing-aggregation.html). 31 | -------------------------------------------------------------------------------- /docs/overview/aggregations/elastic_aggregation_value_count.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_aggregation_value_count 3 | title: "Value count Aggregation" 4 | --- 5 | 6 | The `Value count` aggregation is a single-value metrics aggregation that calculates the number of values that an aggregation is based on. 7 | 8 | In order to use the `Value count` aggregation import the following: 9 | ```scala 10 | import zio.elasticsearch.aggregation.ValueCountAggregation 11 | import zio.elasticsearch.ElasticAggregation.valueCountAggregation 12 | ``` 13 | 14 | You can create a `Value count` aggregation using the `valueCountAggregation` method this way: 15 | ```scala 16 | val aggregation: ValueCountAggregation = valueCountAggregation(name = "valueCountAggregation", field = "stringField") 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Value count` aggregation using the `valueCountAggregation` method this way: 20 | ```scala 21 | val aggregation: ValueCountAggregation = valueCountAggregation(name = "valueCountAggregation", field = Document.stringField) 22 | ``` 23 | 24 | If you want to add aggregation (on the same level), you can use `withAgg` method: 25 | ```scala 26 | val multipleAggregations: MultipleAggregations = valueCountAggregation(name = "valueCountAggregation1", field = Document.stringField).withAgg(valueCountAggregation(name = "valueCountAggregation2", field = Document.intField)) 27 | ``` 28 | 29 | You can find more information about `Value count` aggregation [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html#search-aggregations-metrics-valuecount-aggregation). 30 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_fuzzy.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_fuzzy 3 | title: "Fuzzy Query" 4 | --- 5 | 6 | The `Fuzzy` query returns documents that contain terms similar to the search term, as measured by a [Levenshtein edit distance](https://en.wikipedia.org/wiki/Levenshtein_distance). 7 | 8 | In order to use the `Fuzzy` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.FuzzyQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | ``` 13 | 14 | You can create a `Fuzzy` query using the `fuzzy` method this way: 15 | ```scala 16 | val query: FuzzyQuery = fuzzy(field = "name", value = "test") 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Fuzzy` query using the `fuzzy` method this way: 20 | ```scala 21 | val query: FuzzyQuery = fuzzy(field = Document.name, value = "test") 22 | ``` 23 | 24 | If you want to change the `fuzziness`, you can use `fuzziness` method: 25 | ```scala 26 | val queryWithFuzzinessAuto: FuzzyQuery = fuzzy(field = Document.name, value = "test").fuzziness("AUTO") 27 | ``` 28 | 29 | If you want to change the `maxExpansions`, you can use `maxExpansions` method: 30 | ```scala 31 | val queryWithMaxExpansions: FuzzyQuery = fuzzy(field = Document.name, value = "test").maxExpansions(50) 32 | ``` 33 | 34 | If you want to change the `prefixLength`, you can use `prefixLength` method: 35 | ```scala 36 | val queryWithPrefixLength: FuzzyQuery = fuzzy(field = Document.name, value = "test").prefixLength(3) 37 | ``` 38 | 39 | You can find more information about `Fuzzy` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html). 40 | 41 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_geo_polygon.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_geo_polygon 3 | title: "Geo-polygon Query" 4 | --- 5 | 6 | A query returning hits that only fall within a polygon of points. 7 | 8 | In order to use the `GeoPolygon` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.GeoPolygonQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | ``` 13 | 14 | You can create a `GeoPolygon` query using the `geoPolygon` method with list of coordinates in the following manner: 15 | ```scala 16 | val query: GeoPolygonQuery = geoPolygon(field = "location", List("0, 0", "0, 90", "90, 90", "90, 0")) 17 | ``` 18 | 19 | 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: 20 | ```scala 21 | val query: GeoPolygonQuery = geoPolygon(field = Document.location, List("0, 0", "0, 90", "90, 90", "90, 0")) 22 | ``` 23 | 24 | If you want to change the `_name`, you can use `name` method: 25 | ```scala 26 | val queryWithName: GeoPolygonQuery = geoPolygon(field = "location", coordinates = List("0, 0", "0, 90", "90, 90", "90, 0")).name("name") 27 | ``` 28 | 29 | If you want to change the `validation_method`, you can use `validationMethod` method: 30 | ```scala 31 | import zio.elasticsearch.query.ValidationMethod 32 | 33 | val queryWithValidationMethod: GeoPolygonQuery = geoPolygon(field = "location", coordinates = List("0, 0", "0, 90", "90, 90", "90, 0")).validationMethod(value = ValidationMethod.IgnoreMalformed) 34 | ``` 35 | 36 | You can find more information about `GeoPolygon` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html). 37 | -------------------------------------------------------------------------------- /docs/overview/aggregations/elastic_aggregation_max.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_aggregation_max 3 | title: "Max Aggregation" 4 | --- 5 | 6 | The `Max` aggregation is a single-value metrics aggregation that keeps track and returns the maximum value among the numeric values extracted from the aggregated documents. 7 | 8 | In order to use the `Max` aggregation import the following: 9 | ```scala 10 | import zio.elasticsearch.aggregation.MaxAggregation 11 | import zio.elasticsearch.ElasticAggregation.maxAggregation 12 | ``` 13 | 14 | You can create a `Max` aggregation using the `maxAggregation` method this way: 15 | ```scala 16 | val aggregation: MaxAggregation = maxAggregation(name = "maxAggregation", field = "intField") 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Max` aggregation using the `maxAggregation` method this way: 20 | ```scala 21 | // Document.intField must be number value, because of Max aggregation 22 | val aggregation: MaxAggregation = maxAggregation(name = "maxAggregation", field = Document.intField) 23 | ``` 24 | 25 | If you want to change the `missing`, you can use `missing` method: 26 | ```scala 27 | val aggregationWithMissing: MaxAggregation = maxAggregation(name = "maxAggregation", field = Document.intField).missing(10.0) 28 | ``` 29 | 30 | If you want to add aggregation (on the same level), you can use `withAgg` method: 31 | ```scala 32 | val multipleAggregations: MultipleAggregations = maxAggregation(name = "maxAggregation1", field = Document.intField).withAgg(maxAggregation(name = "maxAggregation2", field = Document.doubleField)) 33 | ``` 34 | 35 | You can find more information about `Max` aggregation [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations-metrics-max-aggregation.html). 36 | -------------------------------------------------------------------------------- /docs/overview/aggregations/elastic_aggregation_sum.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_aggregation_sum 3 | title: "Sum Aggregation" 4 | --- 5 | 6 | The `Sum` aggregation is a single-value metrics aggregation that keeps track and returns the sum value among the numeric values extracted from the aggregated documents. 7 | 8 | In order to use the `Sum` aggregation import the following: 9 | ```scala 10 | import zio.elasticsearch.aggregation.SumAggregation 11 | import zio.elasticsearch.ElasticAggregation.sumAggregation 12 | ``` 13 | 14 | You can create a `Sum` aggregation using the `sumAggregation` method this way: 15 | ```scala 16 | val aggregation: SumAggregation = sumAggregation(name = "sumAggregation", field = "intField") 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Sum` aggregation using the `sumAggregation` method this way: 20 | ```scala 21 | // Document.intField must be number value, because of Sum aggregation 22 | val aggregation: SumAggregation = sumAggregation(name = "sumAggregation", field = Document.intField) 23 | ``` 24 | 25 | If you want to change the `missing` parameter, you can use `missing` method: 26 | ```scala 27 | val aggregationWithMissing: SumAggregation = sumAggregation(name = "sumAggregation", field = Document.intField).missing(10.0) 28 | ``` 29 | 30 | If you want to add aggregation (on the same level), you can use `withAgg` method: 31 | ```scala 32 | val multipleAggregations: MultipleAggregations = sumAggregation(name = "sumAggregation1", field = Document.intField).withAgg(sumAggregation(name = "sumAggregation2", field = Document.doubleField)) 33 | ``` 34 | 35 | You can find more information about `Sum` aggregation [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations-metrics-sum-aggregation.html). 36 | -------------------------------------------------------------------------------- /docs/overview/aggregations/elastic_aggregation_avg.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_aggregation_avg 3 | title: "Avg Aggregation" 4 | --- 5 | 6 | The `Avg` aggregation is a single-value metrics aggregation that keeps track and returns the average value among the numeric values extracted from the aggregated documents. 7 | 8 | In order to use the `Avg` aggregation import the following: 9 | ```scala 10 | import zio.elasticsearch.aggregation.AvgAggregation 11 | import zio.elasticsearch.ElasticAggregation.avgAggregation 12 | ``` 13 | 14 | You can create a `Avg` aggregation using the `avgAggregation` method this way: 15 | ```scala 16 | val aggregation: AvgAggregation = avgAggregation(name = "avgAggregation", field = "intField") 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Avg` aggregation using the `avgAggregation` method this way: 20 | ```scala 21 | // Document.intField must be number value, because of Avg aggregation 22 | val aggregation: AvgAggregation = avgAggregation(name = "avgAggregation", field = Document.intField) 23 | ``` 24 | 25 | If you want to change the `missing` parameter, you can use `missing` method: 26 | ```scala 27 | val aggregationWithMissing: AvgAggregation = avgAggregation(name = "avgAggregation", field = Document.intField).missing(10.0) 28 | ``` 29 | 30 | If you want to add aggregation (on the same level), you can use `withAgg` method: 31 | ```scala 32 | val multipleAggregations: MultipleAggregations = avgAggregation(name = "avgAggregation1", field = Document.intField).withAgg(avgAggregation(name = "avgAggregation2", field = Document.doubleField)) 33 | ``` 34 | 35 | You can find more information about `Avg` aggregation [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations-metrics-avg-aggregation.html). 36 | -------------------------------------------------------------------------------- /docs/overview/aggregations/elastic_aggregation_min.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_aggregation_min 3 | title: "Min Aggregation" 4 | --- 5 | 6 | The `Min` aggregation is a single-value metrics aggregation that keeps track and returns the minimum value among the numeric values extracted from the aggregated documents. 7 | 8 | In order to use the `Min` aggregation import the following: 9 | ```scala 10 | import zio.elasticsearch.aggregation.MinAggregation 11 | import zio.elasticsearch.ElasticAggregation.minAggregation 12 | ``` 13 | 14 | You can create a `Min` aggregation using the `minAggregation` method this way: 15 | ```scala 16 | val aggregation: MinAggregation = minAggregation(name = "minAggregation", field = "intField") 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Min` aggregation using the `minAggregation` method this way: 20 | ```scala 21 | // Document.intField must be number value, because of Min aggregation 22 | val aggregation: MinAggregation = minAggregation(name = "minAggregation", field = Document.intField) 23 | ``` 24 | 25 | If you want to change the `missing` parameter, you can use `missing` method: 26 | ```scala 27 | val aggregationWithMissing: MinAggregation = minAggregation(name = "minAggregation", field = Document.intField).missing(10.0) 28 | ``` 29 | 30 | If you want to add aggregation (on the same level), you can use `withAgg` method: 31 | ```scala 32 | val multipleAggregations: MultipleAggregations = minAggregation(name = "minAggregation1", field = Document.intField).withAgg(minAggregation(name = "minAggregation2", field = Document.doubleField)) 33 | ``` 34 | 35 | You can find more information about `Min` aggregation [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations-metrics-min-aggregation.html). 36 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_simple_query_string.md: -------------------------------------------------------------------------------- 1 | The `SimpleQueryString` query provides a simple query syntax for performing searches across multiple fields. 2 | 3 | To use the `SimpleQueryString` query, import the following: 4 | ```scala 5 | import zio.elasticsearch.query.SimpleQueryStringQuery 6 | import zio.elasticsearch.ElasticQuery._ 7 | ``` 8 | 9 | You can create a `SimpleQueryString` query without specifying `fields` using the `simpleQueryString` method: 10 | ```scala 11 | val query: SimpleQueryStringQuery[Any] = simpleQueryString(query = "name") 12 | ``` 13 | 14 | If you want to specify which fields should be searched, you can use the `fields` method: 15 | ```scala 16 | val query: SimpleQueryStringQuery[Document] = 17 | simpleQueryString(query = "name").fields("stringField1", "stringField2") 18 | ``` 19 | 20 | To define `fields` in a type-safe manner, use the overloaded `fields` method with `field` definitions from your document: 21 | ```scala 22 | val query: SimpleQueryStringQuery[Document] = 23 | simpleQueryString(query = "name").fields(Document.stringField1, Document.stringField2) 24 | ``` 25 | 26 | Alternatively, you can pass a Chunk of `fields`: 27 | ```scala 28 | val query: SimpleQueryStringQuery[Document] = 29 | simpleQueryString(query = "name").fields(Chunk(Document.stringField1, Document.stringField2)) 30 | ``` 31 | 32 | If you want to define the `minimum_should_match` parameter, use the `minimumShouldMatch` method: 33 | ```scala 34 | val query: SimpleQueryStringQuery[Any] = 35 | simpleQueryString(query = "name").minimumShouldMatch(2) 36 | ``` 37 | 38 | You can also construct the query manually with all parameters: 39 | ```scala 40 | val query: SimpleQueryStringQuery[Document] = 41 | SimpleQueryString( 42 | query = "name", 43 | fields = Chunk("stringField"), 44 | minimumShouldMatch = Some(2) 45 | ) 46 | ``` -------------------------------------------------------------------------------- /docs/overview/aggregations/elastic_aggregation_bucket_sort.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_aggregation_bucket_sort 3 | title: "Bucket Sort Aggregation" 4 | --- 5 | 6 | The `BucketSort` aggregation is a parent pipeline aggregation which sorts the buckets of its parent multi-bucket aggregation. Zero or more sort fields may be specified together with the corresponding sort order. 7 | 8 | To create a `BucketSort` aggregation do the following: 9 | ```scala 10 | import zio.elasticsearch.aggregation.BucketSortAggregation 11 | import zio.elasticsearch.ElasticAggregation.bucketSortAggregation 12 | 13 | val aggregation: BucketSortAggregation = bucketSortAggregation(name = "aggregationSort") 14 | ``` 15 | 16 | If you want to change the `from`, you can use `from` method: 17 | ```scala 18 | val aggregationWithFrom: BucketSortAggregation = bucketSortAggregation(name = "aggregationSort").from(5) 19 | ``` 20 | 21 | If you want to change the `size`, you can use `size` method: 22 | ```scala 23 | val aggregationWithSize: BucketSortAggregation = bucketSortAggregation(name = "aggregationSort").size(5) 24 | ``` 25 | 26 | If you want to change the `sort`, you can use `sort` method: 27 | ```scala 28 | import zio.elasticsearch.query.sort.SortByField.{byCount, byKey} 29 | 30 | val aggregationWithSort: BucketSortAggregation = bucketSortAggregation(name = "aggregationSort").sort(byCount, byKey) 31 | ``` 32 | 33 | If you want to add aggregation (on the same level), you can use `withAgg` method: 34 | ```scala 35 | val multipleAggregations: MultipleAggregations = bucketSortAggregation(name = "aggregationSort").withAgg(maxAggregation(name = "maxAggregation", field = Document.doubleField)) 36 | ``` 37 | 38 | You can find more information about `BucketSort` aggregation [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations-pipeline-bucket-sort-aggregation.html). 39 | -------------------------------------------------------------------------------- /docs/overview/requests/elastic_request_delete_by_query.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_request_delete_by_query 3 | title: "Delete By Query Request" 4 | --- 5 | 6 | The `DeleteByQuery` request deletes documents that match the specified query. 7 | 8 | To create a `DeleteById` request do the following: 9 | ```scala 10 | import zio.elasticsearch.ElasticRequest.DeleteByQueryRequest 11 | import zio.elasticsearch.ElasticRequest.deleteByQuery 12 | // this import is required for using `IndexName` 13 | import zio.elasticsearch._ 14 | import zio.elasticsearch.ElasticQuery._ 15 | 16 | val request: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test")) 17 | ``` 18 | 19 | If you want to change the `refresh`, you can use `refresh`, `refreshFalse` or `refreshTrue` method: 20 | ```scala 21 | val requestWithRefresh: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test")).refresh(true) 22 | val requestWithRefreshFalse: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test")).refreshFalse 23 | val requestWithRefreshTrue: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test")).refreshTrue 24 | ``` 25 | 26 | If you want to change the `routing`, you can use the `routing` method: 27 | ```scala 28 | // this import is required for `Routing` also 29 | import zio.elasticsearch._ 30 | 31 | val requestWithRouting: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test")).routing(Routing("routing")) 32 | ``` 33 | 34 | You can find more information about `DeleteByQuery` request [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/docs-delete-by-query.html). 35 | -------------------------------------------------------------------------------- /docs/overview/elastic_executor.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: overview_elastic_executor 3 | title: "Executing Requests" 4 | --- 5 | 6 | In order to get the functional effect of executing a specified Elasticsearch request, you should call the `execute` method defined in the `Elasticsearch`, which returns a `ZIO` that requires an `Elasticsearch`, fails with a `Throwable` and returns the relevant value `A` for that request. 7 | The `Elasticsearch.layer` can be provided using the following import: 8 | 9 | ```scala 10 | import zio.elasticsearch.Elasticsearch 11 | ``` 12 | 13 | However, `Elasticsearch.layer` requires a dependency on the `ElasticExector`. 14 | To provide the dependency on `ElasticExecutor`, you must pass one of the `ZLayer`s from the following import: 15 | 16 | ```scala 17 | import zio.elasticsearch.ElasticExecutor 18 | ``` 19 | 20 | For example, if you want to execute requests on an Elasticsearch server running on `localhost` and port `9200`, you can achieve that in two ways: 21 | - provide the `live` `ZLayer` to your effect, along with a `SttpBackend` and an `ElasticConfig` layer, 22 | - or provide `ElasticExecutor.local` layer along with a `SttpBackend`. 23 | 24 | ```scala 25 | import zio._ 26 | import zio.elasticsearch._ 27 | import sttp.client3.httpclient.zio.HttpClientZioBackend 28 | 29 | val result: RIO[Elasticsearch, Boolean] = 30 | Elasticsearch.execute(ElasticRequest.exists(IndexName("index"), DocumentId("documentId"))) 31 | 32 | // Executing Elasticsearch requests with provided ElasticConfig layer explicitly 33 | result.provide( 34 | ZLayer.succeed(ElasticConfig("localhost", 9200)) >>> ElasticExecutor.live, 35 | Elasticsearch.layer, 36 | HttpClientZioBackend.layer() 37 | ) 38 | 39 | // Executing Elasticsearch requests with local ElasticExecutor 40 | result.provide( 41 | ElasticExecutor.local, 42 | Elasticsearch.layer, 43 | HttpClientZioBackend.layer() 44 | ) 45 | ``` 46 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/sort/options/HasMode.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.sort.options 18 | 19 | import zio.elasticsearch.query.sort.SortMode 20 | 21 | private[elasticsearch] trait HasMode[S <: HasMode[S]] { 22 | 23 | /** 24 | * Sets the `mode` parameter for the [[zio.elasticsearch.query.sort.Sort]]. The `mode` parameter controls how 25 | * Elasticsearch selects a single value from a set of sorted documents. The default `mode` is `Average`. 26 | * 27 | * @param value 28 | * the [[SortMode]] used to pick a value among the sorted set of documents: 29 | * - [[SortMode.Avg]]: uses the average of all values as sort value. Only applicable for number based array fields 30 | * - [[SortMode.Max]]: picks the highest value 31 | * - [[SortMode.Median]]: uses the median of all values as sort value. Only applicable for number based array fields 32 | * - [[SortMode.Min]]: picks the lowest value 33 | * - [[SortMode.Sum]]: uses the sum of all values as sort value. Only applicable for number based array fields 34 | * @return 35 | * an instance of the [[zio.elasticsearch.query.sort.Sort]] enriched with the `mode` parameter. 36 | */ 37 | def mode(value: SortMode): S 38 | } 39 | -------------------------------------------------------------------------------- /docs/overview/fluent_api.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: overview_fluent_api 3 | title: "Fluent API" 4 | --- 5 | 6 | Both Elastic requests and queries offer a fluent API so that we could provide optional parameters in chained method calls for each request or query. 7 | If you are creating a `Bool` query that can possibly contain `must`, `mustNot`, `should`, and `filter` queries, you can just use one of the methods from the `ElasticQuery` object to create any of them and then just fluently chain any other to the original one. 8 | 9 | ```scala 10 | ElasticQuery.must(ElasticQuery.range("version").gte(7).lt(10)).should(ElasticQuery.startsWith("name", "ZIO")) 11 | ``` 12 | 13 | And if we wanted to specify lower and upper bounds for a `range` query: 14 | 15 | ```scala 16 | ElasticQuery.range(User.age).gte(18).lt(100) 17 | ``` 18 | 19 | Fluent API is also supported for parameters like `routing` and `refresh`, for example, if we wanted to add routing and refresh parameters to a `deleteById` request: 20 | Methods `refreshTrue` and `refreshFalse` are just shortcuts for using `refresh(true)` or `refresh(false)`. 21 | 22 | ```scala 23 | ElasticRequest.deleteById(IndexName("index"), DocumentId("documentId")).routing(Routing("routing")).refreshTrue 24 | ``` 25 | 26 | When creating aggregations we can also use `withAgg` method to add another aggregation and return the `MultipleAggregations` type that contains both aggregations. 27 | 28 | ```scala 29 | ElasticAggregation.termsAggregation(name = "firstAggregation", field = "name") 30 | .withAgg(ElasticAggregation.termsAggregation(name = "secondAggregation", field = "age")) 31 | ``` 32 | 33 | Creating `sort` also supports fluent API, as it is shown in the code below: 34 | 35 | ```scala 36 | ElasticSort.sortBy("age").mode(SortMode.Avg) 37 | ElasticSort.sortBy("first_name").missing(Missing.First) 38 | ElasticSort.sortBy("created_at").format("strict_date_optional_time_nanos") 39 | ``` 40 | -------------------------------------------------------------------------------- /docs/overview/aggregations/elastic_aggregation_cardinality.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_aggregation_cardinality 3 | title: "Cardinality Aggregation" 4 | --- 5 | 6 | The `Cardinality` aggregation is a single-value metrics aggregation that calculates an approximate count of distinct values. 7 | 8 | In order to use the `Cardinality` aggregation import the following: 9 | ```scala 10 | import zio.elasticsearch.aggregation.CardinalityAggregation 11 | import zio.elasticsearch.ElasticAggregation.cardinalityAggregation 12 | ``` 13 | 14 | You can create a `Cardinality` aggregation using the `cardinalityAggregation` method in the following manner: 15 | ```scala 16 | val aggregation: CardinalityAggregation = cardinalityAggregation(name = "cardinalityAggregation", field = "intField") 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Cardinality` aggregation using the `cardinalityAggregation` method in the following manner: 20 | ```scala 21 | val aggregation: CardinalityAggregation = cardinalityAggregation(name = "cardinalityAggregation", field = Document.intField) 22 | ``` 23 | 24 | If you want to change the `missing`, you can use `missing` method: 25 | ```scala 26 | val aggregationWithMissing: CardinalityAggregation = cardinalityAggregation(name = "cardinalityAggregation", field = Document.intField).missing(10.0) 27 | ``` 28 | 29 | If you want to add aggregation (on the same level), you can use `withAgg` method: 30 | ```scala 31 | val multipleAggregations: MultipleAggregations = cardinalityAggregation(name = "cardinalityAggregation", field = Document.intField).withAgg(maxAggregation(name = "maxAggregation", field = Document.doubleField)) 32 | ``` 33 | 34 | You can find more information about `Cardinality` aggregation [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations-metrics-cardinality-aggregation.html). 35 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_disjunction_max.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_disjunction_max 3 | title: "Disjunction max Query" 4 | --- 5 | 6 | The `Disjunction max` query returns documents that match one or more query clauses. For documents that match multiple query clauses, the relevance score is set to the highest relevance score from all matching query clauses. When the relevance scores of the returned documents are identical, tie breaker parameter can be used for giving more weight to documents that match multiple query clauses. 7 | 8 | In order to use the `Disjunction max` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.DisjunctionMax 11 | import zio.elasticsearch.ElasticQuery.disjunctionMax 12 | ``` 13 | 14 | You can create a `Disjunction max` query using the `disjunctionMax` method this way: 15 | ```scala 16 | val query: DisjunctionMaxQuery = disjunctionMax(query = term(field = "stringField", value = "test"), queries = exists(field = "intField"), exists(field = "existsField")) 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Disjunction max` query using the `disjunctionMax` method this way: 20 | ```scala 21 | val query: DisjunctionMaxQuery = disjunctionMax(query = term(field = Document.stringField, value = "test"), queries = exists(field = Document.intField), term(field = Document.termField, value = "test")) 22 | ``` 23 | 24 | If you want to change the `tieBreaker`, you can use `tieBreaker` method: 25 | ```scala 26 | val queryWithTieBreaker: DisjunctionMaxQuery = disjunctionMax(query = exists(field = "existsField"), queries = ids(values = "1", "2", "3"), term(field = "termField", value = "test")).tieBreaker(0.5f) 27 | ``` 28 | 29 | You can find more information about `Disjunction max` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html). 30 | -------------------------------------------------------------------------------- /docs/overview/aggregations/elastic_aggregation_stats.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_aggregation_stats 3 | title: "Stats Aggregation" 4 | --- 5 | 6 | The `Stats` aggregation is a multi-value metrics aggregation that provides statistical information (count, sum, min, max and average of a field) over numeric values extracted from the aggregated documents. 7 | 8 | In order to use the `Stats` aggregation import the following: 9 | ```scala 10 | import zio.elasticsearch.aggregation.StatsAggregation 11 | import zio.elasticsearch.ElasticAggregation.statsAggregation 12 | ``` 13 | 14 | You can create a `Stats` aggregation using the `statsAggregation` method this way: 15 | ```scala 16 | val aggregation: StatsAggregation = statsAggregation(name = "statsAggregation", field = "intField") 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Stats` aggregation using the `statsAggregation` method this way: 20 | ```scala 21 | // Document.intField must be number value, because of Stats aggregation 22 | val aggregation: StatsAggregation = statsAggregation(name = "statsAggregation", field = Document.intField) 23 | ``` 24 | 25 | If you want to change the `missing` parameter, you can use `missing` method: 26 | ```scala 27 | val aggregationWithMissing: StatsAggregation = statsAggregation(name = "statsAggregation", field = Document.intField).missing(10.0) 28 | ``` 29 | 30 | If you want to add aggregation (on the same level), you can use `withAgg` method: 31 | ```scala 32 | val multipleAggregations: MultipleAggregations = statsAggregation(name = "statsAggregation1", field = Document.intField).withAgg(statsAggregation(name = "statsAggregation2", field = Document.doubleField)) 33 | ``` 34 | 35 | You can find more information about `Stats` aggregation [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html). 36 | -------------------------------------------------------------------------------- /modules/library/src/main/scala-2/zio/elasticsearch/IndexNameNewtype.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | import zio.prelude.AssertionError.failure 20 | import zio.prelude.Newtype 21 | 22 | trait IndexNameNewtype { 23 | object IndexName extends Newtype[String] { 24 | override def assertion = assertCustom { (name: String) => // scalafix:ok 25 | if (IndexNameValidation.isValid(name)) { 26 | Right(()) 27 | } else { 28 | Left( 29 | failure( 30 | s""" 31 | | - Must be lower case only 32 | | - Cannot include \\, /, *, ?, ", <, >, |, ` `(space character), `,`(comma), #. 33 | | - Cannot include ":"(since 7.0). 34 | | - Cannot be empty 35 | | - Cannot start with -, _, +. 36 | | - Cannot be `.` or `..`. 37 | | - Cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit faster). 38 | | - Names starting with . are deprecated, except for hidden indices and internal indices managed by plugins. 39 | |""".stripMargin 40 | ) 41 | ) 42 | } 43 | } 44 | } 45 | type IndexName = IndexName.Type 46 | } 47 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_nested.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_nested 3 | title: "Nested Query" 4 | --- 5 | 6 | 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. 7 | 8 | In order to use the `Nested` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.NestedQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | ``` 13 | 14 | You can create a `Nested` query using the `nested` method in the following manner: 15 | ```scala 16 | val query: NestedQuery = nested(path = "testField", query = matchAll) 17 | ``` 18 | 19 | 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: 20 | ```scala 21 | val query: NestedQuery = nested(path = Document.subDocumentList, query = matchAll) 22 | ``` 23 | 24 | If you want to change the `ignore_unmapped`, you can use `ignoreUnmapped` method: 25 | ```scala 26 | val queryWithIgnoreUnmapped: NestedQuery = nested(path = Document.subDocumentList, query = matchAll).ignoreUnmapped(true) 27 | ``` 28 | 29 | If you want to change the `inner_hits`, you can use `innerHits` method: 30 | ```scala 31 | import zio.elasticsearch.query.InnerHits 32 | 33 | val queryWithInnerHits: NestedQuery = nested(path = Document.subDocumentList, query = matchAll).innerHits(innerHits = InnerHits.from(5)) 34 | ``` 35 | 36 | If you want to change the `score_mode`, you can use `scoreMode` method: 37 | ```scala 38 | import zio.elasticsearch.query.ScoreMode 39 | 40 | val queryWithScoreMode: NestedQuery = nested(path = Document.subDocumentList, query = matchAll).scoreMode(ScoreMode.Avg) 41 | ``` 42 | 43 | You can find more information about `Nested` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-nested-query.html). 44 | -------------------------------------------------------------------------------- /modules/library/src/main/scala-2/zio/elasticsearch/IndexPatternNewtype.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | import zio.prelude.AssertionError.failure 20 | import zio.prelude.Newtype 21 | 22 | trait IndexPatternNewtype { 23 | object IndexPattern extends Newtype[String] { 24 | override def assertion = assertCustom { (pattern: String) => // scalafix:ok 25 | if (IndexPatternValidation.isValid(pattern)) { 26 | Right(()) 27 | } else { 28 | Left( 29 | failure( 30 | s""" 31 | | - Must be lower case only 32 | | - Cannot include \\, /, ?, ", <, >, |, ` `(space character), `,`(comma), #. 33 | | - Cannot include ":"(since 7.0). 34 | | - Cannot be empty 35 | | - Cannot start with +. 36 | | - Cannot be `.` or `..`. 37 | | - Cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit faster). 38 | | - Patterns starting with . are deprecated, except for hidden indices and internal indices managed by plugins. 39 | |""".stripMargin 40 | ) 41 | ) 42 | } 43 | } 44 | } 45 | type IndexPattern = IndexPattern.Type 46 | } 47 | -------------------------------------------------------------------------------- /docs/overview/aggregations/elastic_aggregation_filter.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_aggregation_filter 3 | title: "Filter Aggregation" 4 | --- 5 | 6 | The `Filter` aggregation is a single bucket aggregation that narrows down the entire set of documents to a specific set that matches a [query](https://lambdaworks.github.io/zio-elasticsearch/overview/elastic_query). 7 | 8 | In order to use the `Filter` aggregation import the following: 9 | ```scala 10 | import zio.elasticsearch.aggregation.FilterAggregation 11 | import zio.elasticsearch.ElasticAggregation.filterAggregation 12 | ``` 13 | 14 | You can create a `Filter` aggregation using the `filterAggregation` method in the following manner: 15 | ```scala 16 | import zio.elasticsearch.ElasticQuery.term 17 | 18 | val aggregation: FilterAggregation = filterAggregation(name = "filterAggregation", query = term(field = Document.stringField, value = "test")) 19 | ``` 20 | 21 | If you want to add aggregation (on the same level), you can use `withAgg` method: 22 | ```scala 23 | import zio.elasticsearch.ElasticQuery.term 24 | 25 | val multipleAggregations: MultipleAggregations = filterAggregation(name = "filterAggregation", query = term(field = Document.stringField, value = "test")).withAgg(maxAggregation(name = "maxAggregation", field = Document.doubleField)) 26 | ``` 27 | 28 | If you want to add another sub-aggregation, you can use `withSubAgg` method: 29 | ```scala 30 | import zio.elasticsearch.ElasticQuery.term 31 | import zio.elasticsearch.ElasticAggregation.maxAggregation 32 | 33 | val aggregationWithSubAgg: FilterAggregation = filterAggregation(name = "filterAggregation", query = term(field = Document.stringField, value = "test")).withSubAgg(maxAggregation(name = "maxAggregation", field = Document.intField)) 34 | ``` 35 | 36 | You can find more information about `Filter` aggregation [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html). 37 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/options/HasScoreMode.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.options 18 | 19 | import zio.elasticsearch.query.ScoreMode 20 | 21 | private[elasticsearch] trait HasScoreMode[Q <: HasScoreMode[Q]] { 22 | 23 | /** 24 | * Sets the [[ScoreMode]] for the [[zio.elasticsearch.query.NestedQuery]]. The [[zio.elasticsearch.query.ScoreMode]] 25 | * specifies how scores of matching documents are combined for the [[zio.elasticsearch.query.NestedQuery]]. 26 | * 27 | * @param scoreMode 28 | * the [[ScoreMode]] to use for the [[zio.elasticsearch.query.NestedQuery]] 29 | * - [[ScoreMode.Avg]]: uses the mean relevance score of all matching child objects 30 | * - [[ScoreMode.Max]]: uses the highest relevance score of all matching child objects 31 | * - [[ScoreMode.Min]]: uses the lowest relevance score of all matching child objects 32 | * - [[ScoreMode.None]]: ignores relevance scores of matching child objects and uses 0 as a score 33 | * - [[ScoreMode.Sum]]: adds together the relevance scores of all matching child objects 34 | * @return 35 | * a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the specified 36 | * [[zio.elasticsearch.query.ScoreMode]]. 37 | */ 38 | def scoreMode(scoreMode: ScoreMode): Q 39 | } 40 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_has_child.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_has_child 3 | title: "Has Child Query" 4 | --- 5 | 6 | The `HasChild` query returns parent documents whose child documents match a provided query. 7 | 8 | To create a `HasChild` query do the following: 9 | ```scala 10 | import zio.elasticsearch.query.HasChildQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | 13 | val query: HasChildQuery = hasChild(childType = "child", query = matches(Document.stringField, "test")) 14 | ``` 15 | 16 | If you want to change `ignore_unmapped`, you can use `ignoreUnmapped` method: 17 | ```scala 18 | val queryWithIgnoreUnmapped: HasChildQuery = hasChild(childType = "child", query = matches(Document.stringField, "test")).ignoreUnmapped(true) 19 | ``` 20 | 21 | If you want to change `inner_hits`, you can use `innerHits` method: 22 | ```scala 23 | import zio.elasticsearch.query.InnerHits 24 | 25 | val queryWithInnerHits: HasChildQuery = hasChild(childType = "child", query = matches(Document.stringField, "test")).innerHits(innerHits = InnerHits.from(5)) 26 | ``` 27 | 28 | If you want to change `max_children`, you can use `maxChildren` method: 29 | ```scala 30 | val queryWithMaxChildren: HasChildQuery = hasChild(childType = "child", query = matches(Document.stringField, "test")).maxChildren(5) 31 | ``` 32 | 33 | If you want to change `min_children`, you can use `minChildren` method: 34 | ```scala 35 | val queryWithMinChildren: HasChildQuery = hasChild(childType = "child", query = matches(Document.stringField, "test")).minChildren(2) 36 | ``` 37 | 38 | If you want to change `score_mode`, you can use `scoreMode` method: 39 | ```scala 40 | import zio.elasticsearch.query.ScoreMode 41 | 42 | val queryWithScoreMode: HasChildQuery = hasChild(childType = "child", query = matches(Document.stringField, "test")).scoreMode(ScoreMode.Max) 43 | ``` 44 | 45 | You can find more information about `HasChild` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html). 46 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_has_parent.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_has_parent 3 | title: "Has Parent Query" 4 | --- 5 | 6 | The `HasParent` query returns child documents whose parent document matches a provided query. 7 | 8 | To create a `HasParent` query do the following: 9 | ```scala 10 | import zio.elasticsearch.query.HasParentQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | 13 | val query: HasParentQuery = hasParent(parentType = "parent", query = matches(Document.stringField, "test")) 14 | ``` 15 | 16 | If you want to change the `boost`, you can use `boost` method: 17 | ```scala 18 | val queryWithBoost: HasParentQuery = hasParent(parentType = "parent", query = matches(Document.stringField, "test")).boost(2.0) 19 | ``` 20 | 21 | If you want to change `ignore_unmapped`, you can use `ignoreUnmapped` method: 22 | ```scala 23 | val queryWithIgnoreUnmapped: HasParentQuery = hasParent(parentType = "parent", query = matches(Document.stringField, "test")).ignoreUnmapped(true) 24 | ``` 25 | 26 | If you want to change `inner_hits`, you can use `innerHits` method: 27 | ```scala 28 | import zio.elasticsearch.query.InnerHits 29 | 30 | val queryWithInnerHits: HasParentQuery = hasParent(parentType = "parent", query = matches(Document.stringField, "test")).innerHits(innerHits = InnerHits.from(5)) 31 | ``` 32 | 33 | If you want to change `score`, you can use `withScore`, `withScoreFalse` or `withScoreTrue` method: 34 | ```scala 35 | val queryWithScore: HasParentQuery = hasParent(parentType = "parent", query = matches(Document.intField, "test")).withScore(true) 36 | val queryWithScoreFalse: HasParentQuery = hasParent(parentType = "parent", query = matches(Document.intField, "test")).withScoreFalse 37 | val queryWithScoreTrue: HasParentQuery = hasParent(parentType = "parent", query = matches(Document.intField, "test")).withScoreTrue 38 | ``` 39 | 40 | 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). 41 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/request/options/HasRefresh.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.request.options 18 | 19 | private[elasticsearch] trait HasRefresh[R <: HasRefresh[R]] { 20 | 21 | /** 22 | * Configures whether or not to refresh the index after the operation in the [[zio.elasticsearch.ElasticRequest]]. 23 | * 24 | * @param value 25 | * should be `true` if the index should be refreshed after the executed operation, `false` otherwise 26 | * @return 27 | * an instance of the [[zio.elasticsearch.ElasticRequest]] enriched with the `refresh` parameter. 28 | */ 29 | def refresh(value: Boolean): R 30 | 31 | /** 32 | * Sets `refresh` parameter to `false` in the [[zio.elasticsearch.ElasticRequest]]. Same as [[refresh]](false). 33 | * 34 | * @return 35 | * a new instance of the [[zio.elasticsearch.ElasticRequest]] with the `refresh` parameter set to `false`. 36 | * @see 37 | * #refresh 38 | */ 39 | final def refreshFalse: R = refresh(false) 40 | 41 | /** 42 | * Sets `refresh` parameter to `true` in the [[zio.elasticsearch.ElasticRequest]]. Same as [[refresh]](true). 43 | * 44 | * @return 45 | * a new instance of the [[zio.elasticsearch.ElasticRequest]] with the `refresh` parameter set to `true`. 46 | * @see 47 | * #refresh 48 | */ 49 | final def refreshTrue: R = refresh(true) 50 | } 51 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_range.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_range 3 | title: "Range Query" 4 | --- 5 | 6 | A query that matches documents that contain terms within a provided range. 7 | 8 | In order to use the `Range` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.RangeQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | ``` 13 | 14 | You can create a `Range` query using the `range` method in the following manner: 15 | ```scala 16 | val query: RangeQuery = range(field = "intField") 17 | ``` 18 | 19 | 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: 20 | ```scala 21 | val query: RangeQuery = range(field = Document.intField) 22 | ``` 23 | 24 | If you want to change `boost`, you can use the `boost` method: 25 | ```scala 26 | val queryWithBoost: RangeQuery = range(field = Document.intField).boost(2.0) 27 | ``` 28 | 29 | If you want to change `format`, you can use the `format` method: 30 | ```scala 31 | val queryWithFormat: RangeQuery = range(field = Document.dateField).format("yyyy-MM-dd") 32 | ``` 33 | 34 | If you want to change `gt` (greater than), you can use the `gt` method: 35 | ```scala 36 | val queryWithGt: RangeQuery = range(field = Document.intField).gt(1) 37 | ``` 38 | 39 | If you want to change `gte` (greater than or equal to), you can use the `gte` method: 40 | ```scala 41 | val queryWithGte: RangeQuery = range(field = Document.intField).gte(1) 42 | ``` 43 | 44 | If you want to change `lt` (less than), you can use the `lt` method: 45 | ```scala 46 | val queryWithLt: RangeQuery = range(field = Document.intField).lt(100) 47 | ``` 48 | 49 | If you want to change `lte` (less than or equal to), you can use the `lte` method: 50 | ```scala 51 | val queryWithLte: RangeQuery = range(field = Document.intField).lte(100) 52 | ``` 53 | 54 | You can find more information about `Range` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-range-query.html). 55 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/options/HasIgnoreUnmapped.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.options 18 | 19 | private[elasticsearch] trait HasIgnoreUnmapped[Q <: HasIgnoreUnmapped[Q]] { 20 | 21 | /** 22 | * Sets the `ignoreUnmapped` parameter to control whether to ignore unmapped fields and return empty hits. 23 | * 24 | * @param value 25 | * the `boolean` value for `ignoreUnmapped` parameter 26 | * @return 27 | * a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the `ignoreUnmapped` value set. 28 | */ 29 | def ignoreUnmapped(value: Boolean): Q 30 | 31 | /** 32 | * Sets the `ignoreUnmapped` parameter to `false` for this [[zio.elasticsearch.query.ElasticQuery]]. Same as 33 | * [[ignoreUnmapped]](false). 34 | * 35 | * @return 36 | * a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the `ignoreUnmapped` value set to `false`. 37 | * @see 38 | * #ignoreUnmapped 39 | */ 40 | final def ignoreUnmappedFalse: Q = ignoreUnmapped(false) 41 | 42 | /** 43 | * Sets the `ignoreUnmapped` parameter to `true` for this [[zio.elasticsearch.query.ElasticQuery]]. Same as 44 | * [[ignoreUnmapped]](true). 45 | * 46 | * @return 47 | * a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the `ignoreUnmapped` value set to `true`. 48 | * @see 49 | * #ignoreUnmapped 50 | */ 51 | final def ignoreUnmappedTrue: Q = ignoreUnmapped(true) 52 | } 53 | -------------------------------------------------------------------------------- /modules/example/src/main/scala/example/GitHubRepo.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example 18 | 19 | import example.external.github.model.RepoResponse 20 | import zio.elasticsearch.FieldAccessorBuilder 21 | import zio.json.{DeriveJsonEncoder, JsonEncoder} 22 | import zio.schema.{DeriveSchema, Schema} 23 | 24 | import java.time.{Instant, LocalDateTime, ZoneId} 25 | 26 | final case class GitHubRepo( 27 | id: String, 28 | organization: String, 29 | name: String, 30 | url: String, 31 | description: Option[String], 32 | lastCommitAt: LocalDateTime, 33 | stars: Int, 34 | forks: Int 35 | ) 36 | 37 | object GitHubRepo { 38 | def fromResponse(response: RepoResponse): GitHubRepo = 39 | GitHubRepo( 40 | id = response.id.toString, 41 | organization = response.owner.organization, 42 | name = response.name, 43 | url = response.url, 44 | description = response.description, 45 | lastCommitAt = LocalDateTime.ofInstant(Instant.parse(response.updatedAt), ZoneId.systemDefault()), 46 | stars = response.stars, 47 | forks = response.forks 48 | ) 49 | 50 | implicit val schema 51 | : Schema.CaseClass8[String, String, String, String, Option[String], LocalDateTime, Int, Int, GitHubRepo] = 52 | DeriveSchema.gen[GitHubRepo] 53 | 54 | val (id, organization, name, url, description, lastCommitAt, stars, forks) = 55 | schema.makeAccessors(FieldAccessorBuilder) 56 | 57 | implicit val encoder: JsonEncoder[GitHubRepo] = DeriveJsonEncoder.gen[GitHubRepo] 58 | } 59 | -------------------------------------------------------------------------------- /docs/overview/aggregations/elastic_aggregation_sampler.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_aggregation_sampler 3 | title: "Sampler Aggregation" 4 | --- 5 | The Sampler aggregation is a single-bucket aggregation that returns a sample of the documents that fall into the aggregation scope. This aggregation is 6 | particularly useful when you want to run sub-aggregations on a representative sample of documents rather than on the entire dataset. 7 | 8 | To use the `Sampler` aggregation, import the following: 9 | ```scala 10 | import zio.elasticsearch.aggregation.SamplerAggregation 11 | import zio.elasticsearch.ElasticAggregation.samplerAggregation 12 | ``` 13 | 14 | A Sampler aggregation must always have at least one sub-aggregation. 15 | You can create a Sampler aggregation with an initial sub-aggregation using the `samplerAggregation` method this way: 16 | ```scala 17 | import zio.elasticsearch.ElasticAggregation.avgAggregation 18 | val aggregation: SamplerAggregation = samplerAggregation( 19 | name = "samplerAggregation", 20 | subAgg = avgAggregation(name = "avgRating", field = Document.intField) 21 | ) 22 | ``` 23 | 24 | If you want to add another sub-aggregation, you can use `withSubAgg` method: 25 | ```scala 26 | val aggregationWithMultipleSubAggs: SamplerAggregation = samplerAggregation( 27 | name = "termsAggregation", 28 | field = Document.stringField 29 | ).withSubAgg(maxAggregation(name = "maxAggregation", field = Document.intField)) 30 | ``` 31 | By default, the `shard_size` parameter for a Sampler aggregation is set to 100. This means that each shard will return a maximum of 100 documents to be 32 | sampled. 33 | If you want to change the `shard_size`, you can use the `maxDocumentsPerShard` method: 34 | ```scala 35 | val aggregationWithShardSize: SamplerAggregation = samplerAggregation( 36 | name = "samplerAggregation", 37 | subAgg = avgAggregation(name = "avgRating", field = Document.intField) 38 | ).maxDocumentsPerShard(500) 39 | ``` 40 | You can find more detailed information about the `Sampler` aggregation in the official Elasticsearch documentation [here](https://www.elastic.co/docs/reference/aggregations/search-aggregations-bucket-sampler-aggregation). -------------------------------------------------------------------------------- /docs/overview/aggregations/elastic_aggregation_percentile_ranks.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_aggregation_percentile_ranks 3 | title: "Percentiles Aggregation" 4 | --- 5 | 6 | The `Percentile ranks` aggregation is a multi-value metrics aggregation that calculates percentile of values at or below a threshold grouped by a specified value. 7 | 8 | In order to use the `Percentile ranks` aggregation import the following: 9 | ```scala 10 | import zio.elasticsearch.aggregation.PercentileRanksAggregation 11 | import zio.elasticsearch.ElasticAggregation.percentileRanksAggregation 12 | ``` 13 | 14 | You can create a `Percentile ranks` aggregation using the `percentileRanksAggregation` method this way: 15 | ```scala 16 | val aggregation: PercentileRanksAggregation = percentileRanksAggregation(field = "intField", name = "percentileRanksAggregation", values = 500, 600) 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Percentile ranks` aggregation using the `percentileRanksAggregation` method this way: 20 | ```scala 21 | // Document.intField must be number value 22 | val aggregation: PercentileRanksAggregation = percentileRanksAggregation(field = Document.intField, name = "percentileRanksAggregation", values = 500, 600) 23 | ``` 24 | 25 | If you want to change the `missing`, you can use `missing` method: 26 | ```scala 27 | val aggregationWithMissing: PercentileRanksAggregation = percentileRanksAggregation(field = Document.intField, name = "percentileRanksAggregation", values = 500, 600).missing(10.0) 28 | ``` 29 | 30 | If you want to add aggregation (on the same level), you can use `withAgg` method: 31 | ```scala 32 | val multipleAggregations: MultipleAggregations = percentileRanksAggregation(field = Document.intField, name = "percentileRanksAggregation1", values = 500, 600).withAgg(percentileRanksAggregation(field = Document.doubleField, name = "percentileRanksAggregation2", values = 500, 600)) 33 | ``` 34 | 35 | You can find more information about `Percentile ranks` aggregation [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-rank-aggregation.html). 36 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_multi_match.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_multi_match 3 | title: "Multi Match Query" 4 | --- 5 | 6 | The `MultiMatch` query builds on the `match` query to allow multi-field queries. 7 | 8 | In order to use the `MultiMatch` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.MultiMatchQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | ``` 13 | 14 | You can create a `MultiMatch` query without specifying fields using the `multiMatch` method this way: 15 | ```scala 16 | val query: MultiMatchQuery = multiMatch(value = "test") 17 | ``` 18 | 19 | If you want to change the `fields` that will be searched, you can use the `fields` method: 20 | ```scala 21 | val query: MultiMatchQuery = multiMatch(value = "test").fields("stringField1", "stringField2") 22 | ``` 23 | 24 | If you want to change the `fields` that will be searched, you can use the `fields` method with the [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) parameters this way: 25 | ```scala 26 | val query: MultiMatchQuery = multiMatch(value = "test").fields(Document.stringField1, Document.stringField2) 27 | ``` 28 | 29 | If you want to change the `boost`, you can use the `boost` method: 30 | ```scala 31 | val queryWithBoost: MultiMatchQuery = multiMatch(value = "test").fields(Document.stringField1, Document.stringField2).boost(2.2) 32 | ``` 33 | 34 | If you want to change the `minimum_should_match`, you can use the `minimumShouldMatch` method: 35 | ```scala 36 | val queryWithMinimumShouldMatch: MultiMatchQuery = multiMatch(value = "test").fields(Document.stringField1, Document.stringField2).minimumShouldMatch(2) 37 | ``` 38 | 39 | If you want to change the `type`, you can use the `matchingType` method: 40 | ```scala 41 | import zio.elasticsearch.query.MultiMatchType._ 42 | 43 | val queryWithType: MultiMatchQuery = multiMatch(value = "test").fields(Document.stringField1, Document.stringField2).matchingType(MostFields) 44 | ``` 45 | 46 | You can find more information about `MultiMatch` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-multi-match-query.html#query-dsl-multi-match-query). 47 | 48 | -------------------------------------------------------------------------------- /docs/overview/aggregations/elastic_aggregation_percentiles.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_aggregation_percentiles 3 | title: "Percentiles Aggregation" 4 | --- 5 | 6 | The `Percentiles` aggregation is a multi-value metrics aggregation that calculates one or more percentiles over numeric values extracted from the aggregated documents. 7 | 8 | In order to use the `Percentiles` aggregation import the following: 9 | ```scala 10 | import zio.elasticsearch.aggregation.PercentilesAggregation 11 | import zio.elasticsearch.ElasticAggregation.percentilesAggregation 12 | ``` 13 | 14 | You can create a `Percentiles` aggregation using the `percentilesAggregation` method this way: 15 | ```scala 16 | val aggregation: PercentilesAggregation = percentilesAggregation(name = "percentilesAggregation", field = "intField") 17 | ``` 18 | 19 | You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Percentiles` aggregation using the `percentilesAggregation` method this way: 20 | ```scala 21 | // Document.intField must be number value 22 | val aggregation: PercentilesAggregation = percentilesAggregation(name = "percentilesAggregation", field = Document.intField) 23 | ``` 24 | 25 | If you want to specify the percentiles you want to calculate, you can use `percents` method: 26 | ```scala 27 | val aggregationWithPercents: PercentilesAggregation = percentilesAggregation(name = "percentilesAggregation", field = Document.intField).percents(15, 50, 70) 28 | ``` 29 | 30 | If you want to change the `missing`, you can use `missing` method: 31 | ```scala 32 | val aggregationWithMissing: PercentilesAggregation = percentilesAggregation(name = "percentilesAggregation", field = Document.intField).missing(10.0) 33 | ``` 34 | 35 | If you want to add aggregation (on the same level), you can use `withAgg` method: 36 | ```scala 37 | val multipleAggregations: MultipleAggregations = percentilesAggregation(name = "percentilesAggregation1", field = Document.intField).withAgg(percentilesAggregation(name = "percentilesAggregation2", field = Document.doubleField)) 38 | ``` 39 | 40 | You can find more information about `Percentiles` aggregation [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations-metrics-percentile-aggregation.html). 41 | 42 | -------------------------------------------------------------------------------- /modules/library/src/main/scala/zio/elasticsearch/query/options/HasCaseInsensitive.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch.query.options 18 | 19 | private[elasticsearch] trait HasCaseInsensitive[Q <: HasCaseInsensitive[Q]] { 20 | 21 | /** 22 | * Sets the `caseInsensitive` parameter for the [[zio.elasticsearch.query.ElasticQuery]]. Case-insensitive queries 23 | * match text regardless of the case of the characters in the query string. By default, queries are case-sensitive. 24 | * 25 | * @param value 26 | * the [[scala.Boolean]] value for `caseInsensitive` parameter 27 | * @return 28 | * a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the `caseInsensitive` value set. 29 | */ 30 | def caseInsensitive(value: Boolean): Q 31 | 32 | /** 33 | * Sets the `caseInsensitive` parameter to `false` for this [[zio.elasticsearch.query.ElasticQuery]]. Same as 34 | * [[caseInsensitive]](false). 35 | * 36 | * @return 37 | * a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the `caseInsensitive` value set to `false`. 38 | * @see 39 | * #caseInsensitive 40 | */ 41 | final def caseInsensitiveFalse: Q = caseInsensitive(false) 42 | 43 | /** 44 | * Sets the `caseInsensitive` parameter to `true` for this [[zio.elasticsearch.query.ElasticQuery]]. Same as 45 | * [[caseInsensitive]](true). 46 | * 47 | * @return 48 | * a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the `caseInsensitive` value set to `true`. 49 | * @see 50 | * #caseInsensitive 51 | */ 52 | final def caseInsensitiveTrue: Q = caseInsensitive(true) 53 | } 54 | -------------------------------------------------------------------------------- /modules/library/src/main/scala-3/zio/elasticsearch/IndexNameValidator.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | import org.apache.commons.lang3.StringUtils 20 | import org.apache.commons.lang3.StringUtils.{equalsAny, startsWithAny} 21 | import zio.Chunk 22 | import zio.prelude.{AssertionError, Validator} 23 | 24 | object IndexNameValidator 25 | extends Validator[String](name => { 26 | def containsAny(string: String, params: Chunk[String]): Boolean = 27 | params.exists(StringUtils.contains(string, _)) 28 | 29 | def isValid(name: String): Boolean = 30 | name.toLowerCase == name && 31 | !startsWithAny(name, "+", "-", "_") && 32 | name.nonEmpty && 33 | !containsAny(string = name, params = Chunk("*", "?", "\"", "<", ">", "|", " ", ",", "#", ":")) && 34 | !equalsAny(name, ".", "..") && 35 | name.getBytes().length <= 255 36 | 37 | if (isValid(name)) { 38 | Right(()) 39 | } else { 40 | Left( 41 | AssertionError.Failure( 42 | s""" 43 | | - Must be lower case only 44 | | - Cannot include \\, /, *, ?, ", <, >, |, ` `(space character), `,`(comma), #. 45 | | - Cannot include ":"(since 7.0). 46 | | - Cannot be empty 47 | | - Cannot start with -, _, +. 48 | | - Cannot be `.` or `..`. 49 | | - Cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit faster). 50 | | - Names starting with . are deprecated, except for hidden indices and internal indices managed by plugins. 51 | |""".stripMargin 52 | ) 53 | ) 54 | } 55 | }) 56 | -------------------------------------------------------------------------------- /modules/library/src/main/scala-3/zio/elasticsearch/IndexPatternValidator.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | import org.apache.commons.lang3.StringUtils 20 | import org.apache.commons.lang3.StringUtils.{equalsAny, startsWithAny} 21 | import zio.Chunk 22 | import zio.prelude.{AssertionError, Validator} 23 | 24 | object IndexPatternValidator 25 | extends Validator[String](pattern => { 26 | def containsAny(string: String, params: Chunk[String]): Boolean = 27 | params.exists(StringUtils.contains(string, _)) 28 | 29 | def isValid(pattern: String): Boolean = 30 | pattern.toLowerCase == pattern && 31 | !startsWithAny(pattern, "+") && 32 | pattern.nonEmpty && 33 | !containsAny(string = pattern, params = Chunk("?", "\"", "<", ">", "|", " ", ",", "#", ":")) && 34 | !equalsAny(pattern, ".", "..") && 35 | pattern.getBytes().length <= 255 36 | 37 | if (isValid(pattern)) { 38 | Right(()) 39 | } else { 40 | Left( 41 | AssertionError.Failure( 42 | s""" 43 | | - Must be lower case only 44 | | - Cannot include \\, /, ?, ", <, >, |, ` `(space character), `,`(comma), #. 45 | | - Cannot include ":"(since 7.0). 46 | | - Cannot be empty 47 | | - Cannot start with +. 48 | | - Cannot be `.` or `..`. 49 | | - Cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit faster). 50 | | - Patterns starting with . are deprecated, except for hidden indices and internal indices managed by plugins. 51 | |""".stripMargin 52 | ) 53 | ) 54 | } 55 | }) 56 | -------------------------------------------------------------------------------- /docs/overview/queries/elastic_query_wildcard.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: elastic_query_wildcard 3 | title: "Wildcard Query" 4 | --- 5 | 6 | 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. 7 | 8 | In order to use the `Wildcard` query import the following: 9 | ```scala 10 | import zio.elasticsearch.query.WildcardQuery 11 | import zio.elasticsearch.ElasticQuery._ 12 | ``` 13 | 14 | The `Wildcard` query can be created with `contains`, `startsWith` or `wildcard` method. 15 | The `contains` method is adjusted `wildcard` method, that returns documents that contain terms containing provided text. 16 | The `startsWith` method is adjusted `wildcard` method that returns documents that contain terms starting with provided text. 17 | 18 | To create a `Wildcard` query use one of the following methods: 19 | ```scala 20 | val query: WildcardQuery = contains(field = "name", value = "a") 21 | val query: WildcardQuery = startsWith(field = "name", value = "a") 22 | val query: WildcardQuery = wildcard(field = "name", value = "a*a*") 23 | ``` 24 | 25 | To create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Wildcard` query use one of the following methods: 26 | ```scala 27 | val query: WildcardQuery = contains(field = Document.name, value = "a") 28 | val query: WildcardQuery = startsWith(field = Document.name, value = "a") 29 | val query: WildcardQuery = wildcard(field = Document.name, value = "a*a*") 30 | ``` 31 | 32 | If you want to change the `boost`, you can use `boost` method: 33 | ```scala 34 | val queryWithBoost: WildcardQuery = contains(field = Document.name, value = "test").boost(2.0) 35 | ``` 36 | 37 | If you want to change the `case_insensitive`, you can use `caseInsensitive`, `caseInsensitiveFalse` or `caseInsensitiveTrue` method: 38 | ```scala 39 | val queryWithCaseInsensitive: WildcardQuery = contains(field = Document.name, value = "a").caseInsensitive(true) 40 | val queryWithCaseInsensitiveFalse: WildcardQuery = contains(field = Document.name, value = "a").caseInsensitiveFalse 41 | val queryWithCaseInsensitiveTrue: WildcardQuery = contains(field = Document.name, value = "a").caseInsensitiveTrue 42 | ``` 43 | 44 | 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). 45 | -------------------------------------------------------------------------------- /modules/library/src/main/scala-2/zio/elasticsearch/MultiIndex.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 LambdaWorks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zio.elasticsearch 18 | 19 | import zio.Chunk 20 | 21 | trait IndexSelector[A] { 22 | def toSelector(a: A): String 23 | } 24 | 25 | object IndexSelector { 26 | 27 | implicit object IndexNameSelector extends IndexSelector[IndexName] { 28 | def toSelector(name: IndexName): String = 29 | IndexName.unwrap(name) 30 | } 31 | 32 | implicit object IndexPatternSelector extends IndexSelector[IndexPattern] { 33 | def toSelector(pattern: IndexPattern): String = 34 | IndexPattern.unwrap(pattern) 35 | } 36 | 37 | implicit object MultiIndexSelector extends IndexSelector[MultiIndex] { 38 | def toSelector(multi: MultiIndex): String = 39 | multi.indices.mkString(",") 40 | } 41 | 42 | implicit class IndexNameSyntax[A](a: A)(implicit IS: IndexSelector[A]) { 43 | def toSelector: String = 44 | IS.toSelector(a) 45 | } 46 | 47 | } 48 | 49 | private[elasticsearch] final case class MultiIndex private[elasticsearch] (indices: Chunk[String]) { self => 50 | 51 | def names(name: IndexName, names: IndexName*): MultiIndex = 52 | self.copy(indices = indices ++ Chunk.fromIterable(name.toString +: names.map(IndexName.unwrap))) 53 | 54 | def patterns(pattern: IndexPattern, patterns: IndexPattern*): MultiIndex = 55 | self.copy(indices = indices ++ Chunk.fromIterable(pattern.toString +: patterns.map(IndexPattern.unwrap))) 56 | } 57 | 58 | object MultiIndex { 59 | def names(name: IndexName, names: IndexName*): MultiIndex = 60 | MultiIndex(Chunk.fromIterable(name.toString +: names.map(IndexName.unwrap))) 61 | 62 | def patterns(pattern: IndexPattern, patterns: IndexPattern*): MultiIndex = 63 | MultiIndex(Chunk.fromIterable(pattern.toString +: patterns.map(IndexPattern.unwrap))) 64 | } 65 | --------------------------------------------------------------------------------