├── config ├── version.txt ├── version-serverless.txt ├── forbidden-apis.txt └── checkstyle │ └── header.java.txt ├── CODE_OF_CONDUCT.md ├── NOTICE.txt ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── examples ├── realworld-app │ ├── rw-logo.png │ ├── rw-database │ │ ├── src │ │ │ ├── test │ │ │ │ └── resources │ │ │ │ │ └── test.properties │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── realworld │ │ │ │ ├── document │ │ │ │ ├── article │ │ │ │ │ ├── TagsDTO.java │ │ │ │ │ ├── ArticlesDTO.java │ │ │ │ │ ├── ArticleUpdateDTO.java │ │ │ │ │ └── ArticleCreationDTO.java │ │ │ │ ├── comment │ │ │ │ │ ├── CommentsDTO.java │ │ │ │ │ ├── CommentCreationDTO.java │ │ │ │ │ ├── Comment.java │ │ │ │ │ └── CommentForListDTO.java │ │ │ │ ├── exception │ │ │ │ │ ├── UnauthorizedException.java │ │ │ │ │ ├── ResourceNotFoundException.java │ │ │ │ │ └── ResourceAlreadyExistsException.java │ │ │ │ └── user │ │ │ │ │ ├── Author.java │ │ │ │ │ ├── User.java │ │ │ │ │ ├── LoginDTO.java │ │ │ │ │ ├── RegisterDTO.java │ │ │ │ │ ├── Profile.java │ │ │ │ │ └── UserDTO.java │ │ │ │ ├── utils │ │ │ │ ├── UserIdPair.java │ │ │ │ ├── ArticleIdPair.java │ │ │ │ └── Utility.java │ │ │ │ └── constant │ │ │ │ └── Constants.java │ │ └── build.gradle │ ├── settings.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── rw-server │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ │ └── java │ │ │ │ └── realworld │ │ │ │ ├── SpringBootApp.java │ │ │ │ └── config │ │ │ │ └── DefaultProperties.java │ │ └── build.gradle │ ├── rw-rest │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── realworld │ │ │ └── rest │ │ │ └── error │ │ │ └── RestError.java │ ├── build.gradle │ └── docker-compose.yaml └── esql-article │ ├── src │ └── main │ │ └── java │ │ └── co │ │ └── elastic │ │ └── clients │ │ └── esql │ │ └── article │ │ └── Book.java │ └── build.gradle.kts ├── docs ├── reference │ ├── images │ │ ├── es-endpoint.jpg │ │ ├── create-api-key.png │ │ ├── otel-waterfall-retries.jpg │ │ ├── otel-waterfall-instrumented.jpg │ │ └── otel-waterfall-instrumented-without-http.jpg │ ├── _snippets │ │ ├── legacy-rest-client.md │ │ └── doc-tests-blurb.md │ ├── setup │ │ └── index.md │ ├── transport │ │ ├── rest5-client │ │ │ ├── usage │ │ │ │ ├── index.md │ │ │ │ └── logging.md │ │ │ ├── index.md │ │ │ └── config │ │ │ │ ├── index.md │ │ │ │ ├── number_of_threads.md │ │ │ │ └── others.md │ │ └── rest-client │ │ │ ├── usage │ │ │ ├── index.md │ │ │ ├── javadoc.md │ │ │ ├── dependencies.md │ │ │ └── maven.md │ │ │ ├── sniffer │ │ │ ├── index.md │ │ │ ├── javadoc.md │ │ │ └── maven_repository.md │ │ │ ├── index.md │ │ │ └── config │ │ │ ├── index.md │ │ │ ├── number_of_threads.md │ │ │ └── others.md │ ├── troubleshooting │ │ ├── could-not-resolve-dependencies.md │ │ ├── no-class-def-found-error.md │ │ └── index.md │ ├── external-resources.md │ ├── javadoc-source-code.md │ ├── license.md │ ├── api-conventions │ │ ├── method-naming.md │ │ ├── exception-conventions.md │ │ ├── index.md │ │ ├── package-structure.md │ │ ├── object-lifecycles.md │ │ └── blocking-async.md │ └── usage │ │ └── index.md ├── release-notes │ ├── toc.yml │ ├── index.md │ └── 9-0-4.md ├── design │ └── Readme.md ├── docset.yml └── external-resources.md ├── CHANGELOG.md ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── feature_request.yml │ └── bug.yml └── workflows │ ├── gradle-wrapper-validation.yml │ ├── docs-cleanup.yml │ ├── backport.yml │ ├── docs-build.yml │ ├── unit-tests.yml │ ├── checkstyle.yml │ ├── issue-ingest-stats.yml │ └── make-assemble.yml ├── example-transports ├── README.md ├── src │ └── test │ │ └── java │ │ └── co │ │ └── elastic │ │ └── clients │ │ └── transport │ │ ├── netty │ │ └── NettyClientTest.java │ │ └── rest_client │ │ └── RestTransportClientTest.java └── build.gradle.kts ├── rest5-client ├── src │ ├── test │ │ ├── resources │ │ │ └── co │ │ │ │ └── elastic │ │ │ │ └── clients │ │ │ │ └── transport │ │ │ │ └── rest5_client │ │ │ │ └── low_level │ │ │ │ ├── test.der │ │ │ │ ├── testks.jks │ │ │ │ ├── test_truststore.jks │ │ │ │ ├── sniffer │ │ │ │ ├── readme.txt │ │ │ │ ├── es6_nodes_publication_address_format.json │ │ │ │ └── es7_nodes_publication_address_format.json │ │ │ │ └── test.crt │ │ └── java │ │ │ └── co │ │ │ └── elastic │ │ │ └── clients │ │ │ └── transport │ │ │ └── rest5_client │ │ │ └── low_level │ │ │ └── sniffer │ │ │ └── MockNodesSniffer.java │ └── main │ │ └── java │ │ └── co │ │ └── elastic │ │ └── clients │ │ └── transport │ │ └── rest5_client │ │ └── low_level │ │ ├── Constants.java │ │ ├── sniffer │ │ └── NodesSniffer.java │ │ ├── HttpGetWithEntity.java │ │ └── HttpDeleteWithEntity.java └── README.md ├── java-client └── src │ ├── test │ ├── resources │ │ └── co │ │ │ └── elastic │ │ │ └── clients │ │ │ ├── documentation │ │ │ └── api_conventions │ │ │ │ └── some-index.json │ │ │ └── elasticsearch │ │ │ └── spec_issues │ │ │ ├── issue-0078.json │ │ │ ├── issue-0107-response.json │ │ │ └── issue-0057-response.json │ └── java │ │ ├── co │ │ └── elastic │ │ │ └── clients │ │ │ ├── elasticsearch │ │ │ ├── experiments │ │ │ │ ├── package-info.java │ │ │ │ ├── containers │ │ │ │ │ └── SomeUnionVariant.java │ │ │ │ ├── api │ │ │ │ │ ├── FooResponse.java │ │ │ │ │ ├── query2 │ │ │ │ │ │ └── QueryTest.java │ │ │ │ │ └── DateMathTimeUnit.java │ │ │ │ ├── UnionVariant.java │ │ │ │ └── base │ │ │ │ │ └── PrimitiveUtils.java │ │ │ └── model │ │ │ │ └── package-info.java │ │ │ ├── transport │ │ │ ├── VersionInfoTest.java │ │ │ └── endpoints │ │ │ │ └── BooleanEndpointTest.java │ │ │ ├── util │ │ │ ├── DuplicateResourceFinderTest.java │ │ │ └── PairTest.java │ │ │ ├── json │ │ │ └── JsonpDeserializerTest.java │ │ │ └── documentation │ │ │ └── usage │ │ │ └── Product.java │ │ └── com │ │ └── fasterxml │ │ └── jackson │ │ └── databind │ │ └── ext │ │ └── CoreXMLSerializers.java │ ├── main │ ├── resources │ │ └── co │ │ │ └── elastic │ │ │ └── clients │ │ │ └── version.properties │ └── java │ │ └── co │ │ └── elastic │ │ └── clients │ │ ├── elasticsearch │ │ ├── _helpers │ │ │ ├── package-info.java │ │ │ └── esql │ │ │ │ ├── jdbc │ │ │ │ ├── JdbcWrapper.java │ │ │ │ └── Cursor.java │ │ │ │ └── EsqlAdapter.java │ │ ├── _types │ │ │ ├── AcknowledgedResponse.java │ │ │ ├── query_dsl │ │ │ │ ├── PinnedQueryVariant.java │ │ │ │ ├── GeoGridQueryVariant.java │ │ │ │ ├── IntervalsQueryVariant.java │ │ │ │ ├── SparseVectorQueryVariant.java │ │ │ │ └── QueryVariant.java │ │ │ └── RankVariant.java │ │ ├── transform │ │ │ └── SyncVariant.java │ │ ├── ingest │ │ │ ├── DatabaseConfigurationVariant.java │ │ │ └── DatabaseConfigurationFullVariant.java │ │ └── watcher │ │ │ ├── InputVariant.java │ │ │ └── TriggerVariant.java │ │ ├── json │ │ ├── JsonpSerializer.java │ │ ├── BufferingJsonpMapper.java │ │ ├── JsonpSerializable.java │ │ ├── JsonBuffer.java │ │ ├── jackson │ │ │ ├── Jackson3Utils.java │ │ │ └── JacksonUtils.java │ │ ├── BufferingJsonParser.java │ │ ├── BufferingJsonGenerator.java │ │ ├── NdJsonpSerializable.java │ │ ├── JsonpMapperFeatures.java │ │ ├── JsonpDeserializable.java │ │ ├── ToStringMapper.java │ │ ├── UnexpectedJsonEventException.java │ │ └── JsonLocationImpl.java │ │ ├── util │ │ ├── ObjectBuilder.java │ │ ├── ContentType.java │ │ ├── OpenTaggedUnion.java │ │ ├── AllowForbiddenApis.java │ │ ├── TaggedUnion.java │ │ ├── TriConsumer.java │ │ ├── QuadConsumer.java │ │ ├── TriFunction.java │ │ └── VisibleForTesting.java │ │ └── transport │ │ ├── ResponseBase.java │ │ ├── ElasticsearchTransport.java │ │ ├── TransportInfo.java │ │ ├── JsonEndpoint.java │ │ ├── endpoints │ │ └── BooleanResponse.java │ │ └── WithUriParameter.java │ └── main-flavored │ └── java │ └── co │ └── elastic │ └── clients │ └── transport │ └── VersionInfo.java ├── .backportrc.json ├── .buildkite ├── pipeline.yml └── release_central.yml ├── .gitignore ├── settings.gradle.kts ├── .ci └── release_central.sh ├── tools └── build.gradle.kts └── CONTRIBUTING.md /config/version.txt: -------------------------------------------------------------------------------- 1 | 9.3.0 2 | -------------------------------------------------------------------------------- /config/version-serverless.txt: -------------------------------------------------------------------------------- 1 | 1.0.0 2 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | See: https://www.elastic.co/community/codeofconduct 2 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Elasticsearch Java Client 2 | Copyright 2021 Elasticsearch B.V. 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/elasticsearch-java/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /examples/realworld-app/rw-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/elasticsearch-java/HEAD/examples/realworld-app/rw-logo.png -------------------------------------------------------------------------------- /docs/reference/images/es-endpoint.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/elasticsearch-java/HEAD/docs/reference/images/es-endpoint.jpg -------------------------------------------------------------------------------- /docs/reference/images/create-api-key.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/elasticsearch-java/HEAD/docs/reference/images/create-api-key.png -------------------------------------------------------------------------------- /docs/reference/images/otel-waterfall-retries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/elasticsearch-java/HEAD/docs/reference/images/otel-waterfall-retries.jpg -------------------------------------------------------------------------------- /docs/reference/images/otel-waterfall-instrumented.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/elasticsearch-java/HEAD/docs/reference/images/otel-waterfall-instrumented.jpg -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | See the [release notes](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/release_notes.html) sections in the main documentation. 2 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/test/resources/test.properties: -------------------------------------------------------------------------------- 1 | ### 2 | # Test properties 3 | ### 4 | jwt.signing.key=c3VjaGFteXN0ZXJ5b3Vyc3VwZXJzZWNyZXR3b3c= 5 | -------------------------------------------------------------------------------- /examples/realworld-app/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = "realworld-app" 2 | includeBuild("rw-server") 3 | includeBuild("rw-database") 4 | includeBuild("rw-rest") 5 | 6 | -------------------------------------------------------------------------------- /examples/realworld-app/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/elasticsearch-java/HEAD/examples/realworld-app/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /config/forbidden-apis.txt: -------------------------------------------------------------------------------- 1 | @defaultMessage JsonProvider.provider() should not be used directly. Use JsonpUtils#provider() instead. 2 | jakarta.json.spi.JsonProvider#provider() 3 | 4 | -------------------------------------------------------------------------------- /docs/release-notes/toc.yml: -------------------------------------------------------------------------------- 1 | toc: 2 | - file: index.md 3 | - file: known-issues.md 4 | - file: 9-2-0.md 5 | - file: 9-1-0.md 6 | - file: 9-0-4.md 7 | - file: 9-0-0.md 8 | -------------------------------------------------------------------------------- /docs/reference/images/otel-waterfall-instrumented-without-http.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/elasticsearch-java/HEAD/docs/reference/images/otel-waterfall-instrumented-without-http.jpg -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | contact_links: 3 | - name: Question 4 | url: https://discuss.elastic.co/tag/language-clients 5 | about: Ask (and answer) questions here. 6 | -------------------------------------------------------------------------------- /example-transports/README.md: -------------------------------------------------------------------------------- 1 | This directory contains experimental implementations of the `TransportHttpClient` interface. They are to be used as examples and inspiration and should not be considered production-ready. 2 | -------------------------------------------------------------------------------- /docs/reference/_snippets/legacy-rest-client.md: -------------------------------------------------------------------------------- 1 | :::{note} 2 | This is the legacy RestClient. Please migrate to [Rest5Client](/reference/transport/rest5-client/index.md), a drop-in replacement with an up-to-date http library. 3 | ::: 4 | -------------------------------------------------------------------------------- /docs/reference/_snippets/doc-tests-blurb.md: -------------------------------------------------------------------------------- 1 | The source code for the examples above can be found in the [Java API Client tests](https://github.com/elastic/elasticsearch-java/tree/main/java-client/src/test/java/co/elastic/clients/documentation). 2 | -------------------------------------------------------------------------------- /rest5-client/src/test/resources/co/elastic/clients/transport/rest5_client/low_level/test.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/elasticsearch-java/HEAD/rest5-client/src/test/resources/co/elastic/clients/transport/rest5_client/low_level/test.der -------------------------------------------------------------------------------- /rest5-client/src/test/resources/co/elastic/clients/transport/rest5_client/low_level/testks.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/elasticsearch-java/HEAD/rest5-client/src/test/resources/co/elastic/clients/transport/rest5_client/low_level/testks.jks -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /rest5-client/src/test/resources/co/elastic/clients/transport/rest5_client/low_level/test_truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/elasticsearch-java/HEAD/rest5-client/src/test/resources/co/elastic/clients/transport/rest5_client/low_level/test_truststore.jks -------------------------------------------------------------------------------- /java-client/src/test/resources/co/elastic/clients/documentation/api_conventions/some-index.json: -------------------------------------------------------------------------------- 1 | { 2 | "settings": { 3 | "number_of_shards": 1 4 | }, 5 | "mappings": { 6 | "properties": { 7 | "field1": { "type": "text" } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /docs/reference/setup/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/_setup.html 4 | --- 5 | 6 | # Setup [_setup] 7 | 8 | * [](installation.md) 9 | * [](connecting.md) 10 | * [](opentelemetry.md) 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /docs/design/Readme.md: -------------------------------------------------------------------------------- 1 | This directory contains _architecture decision records_ that explain design choices for the Java client. 2 | 3 | An architecture decision record (ADR) is a document that captures an important architectural decision made along with its context and consequences. See https://adr.github.io/ 4 | -------------------------------------------------------------------------------- /.github/workflows/gradle-wrapper-validation.yml: -------------------------------------------------------------------------------- 1 | name: "Validate Gradle Wrapper" 2 | on: [push, pull_request] 3 | 4 | jobs: 5 | validation: 6 | name: "Validation" 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v4 10 | - uses: gradle/wrapper-validation-action@v2 11 | -------------------------------------------------------------------------------- /java-client/src/test/resources/co/elastic/clients/elasticsearch/spec_issues/issue-0078.json: -------------------------------------------------------------------------------- 1 | { 2 | "size": 9999, 3 | "query": { 4 | "match_all": {} 5 | }, 6 | "sort": [ 7 | { 8 | "modify_time": { 9 | "order": "desc" 10 | } 11 | } 12 | ], 13 | "track_total_hits": 2147483647 14 | } 15 | -------------------------------------------------------------------------------- /examples/realworld-app/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /.github/workflows/docs-cleanup.yml: -------------------------------------------------------------------------------- 1 | name: docs-cleanup 2 | 3 | on: 4 | pull_request_target: 5 | types: 6 | - closed 7 | 8 | jobs: 9 | docs-preview: 10 | uses: elastic/docs-builder/.github/workflows/preview-cleanup.yml@main 11 | permissions: 12 | contents: none 13 | id-token: write 14 | deployments: write 15 | -------------------------------------------------------------------------------- /.backportrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "upstream": "elastic/elasticsearch-java", 3 | "targetBranchChoices": [ 4 | "main", 5 | "8.0", 6 | "7.17", 7 | "7.16" 8 | ], 9 | "targetPRLabels": ["backport"], 10 | "branchLabelMapping": { 11 | "^v8.1.0$": "main", 12 | "^v(\\d+).(\\d+).\\d+(?:-(?:alpha|beta|rc)\\d+)?$": "$1.$2" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /docs/reference/transport/rest5-client/usage/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | navigation_title: Getting started 3 | --- 4 | 5 | # Getting started with the {{es}} Java Rest 5 client 6 | 7 | This section describes how to get started with the low-level REST client from getting the artifact to using it in an application. 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.github/workflows/backport.yml: -------------------------------------------------------------------------------- 1 | name: Backport 2 | on: 3 | pull_request: 4 | types: 5 | - closed 6 | - labeled 7 | 8 | jobs: 9 | backport: 10 | runs-on: ubuntu-latest 11 | name: Backport 12 | steps: 13 | - name: Backport 14 | uses: tibdex/backport@v1 15 | with: 16 | github_token: ${{ secrets.GITHUB_TOKEN }} 17 | -------------------------------------------------------------------------------- /docs/reference/troubleshooting/could-not-resolve-dependencies.md: -------------------------------------------------------------------------------- 1 | --- 2 | navigation_title: Could not resolve dependencies 3 | mapped_pages: 4 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/could-not-resolve-dependencies.html 5 | --- 6 | 7 | # Could not resolve dependencies 8 | 9 | Check the [Known Issues](/release-notes/known-issues.md#known-issues-8-16-7) 10 | -------------------------------------------------------------------------------- /.buildkite/pipeline.yml: -------------------------------------------------------------------------------- 1 | steps: 2 | - label: ":java: :elasticsearch: Elasticsearch Java API client DRA - {{matrix.workflow}}" 3 | agents: 4 | provider: "gcp" 5 | branches: [ "main", "7.17", "8.17", "8.18", "8.x", "9.0" ] 6 | matrix: 7 | setup: 8 | workflow: 9 | - "snapshot" 10 | - "staging" 11 | command: ".ci/release_dra.sh {{matrix.workflow}}" 12 | -------------------------------------------------------------------------------- /rest5-client/src/test/resources/co/elastic/clients/transport/rest5_client/low_level/sniffer/readme.txt: -------------------------------------------------------------------------------- 1 | `*_node_http.json` contains files created by spinning up toy clusters with a 2 | few nodes in different configurations locally at various versions. They are 3 | for testing `ElasticsearchNodesSniffer` against different versions of 4 | Elasticsearch. 5 | 6 | See create_test_nodes_info.bash for how to create these. 7 | -------------------------------------------------------------------------------- /docs/reference/troubleshooting/no-class-def-found-error.md: -------------------------------------------------------------------------------- 1 | --- 2 | navigation_title: "NoClassDefFoundError: LogFactory" 3 | mapped_pages: 4 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/no-class-def-found-error.html 5 | --- 6 | 7 | # `NoClassDefFoundError`: org/apache/commons/logging/LogFactory 8 | 9 | Check the [Known Issues](/release-notes/known-issues.md#known-issues-9-0-0) 10 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | ### 2 | # Application Settings 3 | ### 4 | server.port=8080 5 | server.address=localhost 6 | logging.level.org.springframework.web=DEBUG 7 | jwt.signing.key=c3VjaGFteXN0ZXJ5b3Vyc3VwZXJzZWNyZXR3b3c= 8 | ### 9 | # Elasticsearch Settings 10 | ### 11 | elasticsearch.server.url=http://localhost:9200 12 | elasticsearch.api.key=VnVhQ2ZHY0JDZGJrU... 13 | 14 | -------------------------------------------------------------------------------- /.github/workflows/docs-build.yml: -------------------------------------------------------------------------------- 1 | name: docs-build 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request_target: ~ 8 | merge_group: ~ 9 | 10 | jobs: 11 | docs-preview: 12 | uses: elastic/docs-builder/.github/workflows/preview-build.yml@main 13 | with: 14 | path-pattern: docs/** 15 | permissions: 16 | deployments: write 17 | id-token: write 18 | contents: read 19 | pull-requests: write 20 | -------------------------------------------------------------------------------- /docs/reference/troubleshooting/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/troubleshooting.html 4 | --- 5 | 6 | # Troubleshooting 7 | 8 | ## Exceptions 9 | 10 | * [](missing-required-property.md) 11 | * [](no-such-method-request-options.md) 12 | * [](io-reactor-errors.md) 13 | * [](could-not-resolve-dependencies.md) 14 | * [](no-class-def-found-error.md) 15 | 16 | ## Miscellaneous 17 | 18 | * [](serialize-without-typed-keys.md) 19 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-server/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'org.springframework.boot' version '3.2.1' 4 | id 'io.spring.dependency-management' version '1.1.4' 5 | } 6 | 7 | group = 'realworldapp' 8 | version = '0.0.1-SNAPSHOT' 9 | 10 | java { 11 | sourceCompatibility = '21' 12 | } 13 | 14 | repositories { 15 | mavenCentral() 16 | } 17 | 18 | dependencies { 19 | implementation('org.springframework.boot:spring-boot-starter:3.2.0') 20 | implementation('realworldapp:rw-rest') 21 | } 22 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-rest/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'org.springframework.boot' version '3.2.1' 4 | id 'io.spring.dependency-management' version '1.1.4' 5 | } 6 | 7 | group = 'realworldapp' 8 | version = '0.0.1-SNAPSHOT' 9 | 10 | java { 11 | sourceCompatibility = '21' 12 | } 13 | 14 | repositories { 15 | mavenCentral() 16 | } 17 | 18 | dependencies { 19 | implementation('org.springframework.boot:spring-boot-starter-web:3.2.0') 20 | implementation('realworldapp:rw-database') 21 | } 22 | 23 | -------------------------------------------------------------------------------- /docs/docset.yml: -------------------------------------------------------------------------------- 1 | project: 'Java API Client' 2 | products: 3 | - id: elasticsearch-client 4 | exclude: 5 | - external-resources.md 6 | - design/* 7 | cross_links: 8 | - docs-content 9 | - elasticsearch 10 | toc: 11 | - toc: reference 12 | - toc: release-notes 13 | subs: 14 | es: "Elasticsearch" 15 | version: "9.2.0" 16 | # Not used by docs-builder, but present in `% :::{include-bloc}` preprocessing directives (see IncludeExpander.java) 17 | doc-tests-src: "../../java-client/src/test/java/co/elastic/clients/documentation" 18 | -------------------------------------------------------------------------------- /.github/workflows/unit-tests.yml: -------------------------------------------------------------------------------- 1 | name: Java Unit Tests 2 | 3 | on: 4 | workflow_run: 5 | workflows: ['Validate Gradle Wrapper'] 6 | types: [completed] 7 | branches: 8 | - 'main' 9 | 10 | jobs: 11 | tests: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | 17 | - name: Set up JDK 17 18 | uses: actions/setup-java@v3 19 | with: 20 | java-version: '17' 21 | distribution: 'temurin' 22 | - name: Run java client tests 23 | run: ./gradlew test -p java-client 24 | -------------------------------------------------------------------------------- /docs/reference/transport/rest-client/usage/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/java-rest-low-usage.html 4 | navigation_title: Getting started 5 | --- 6 | 7 | # Getting started with the {{es}} Java REST client [java-rest-low-usage] 8 | 9 | :::{include} /reference/_snippets/legacy-rest-client.md 10 | ::: 11 | 12 | This section describes how to get started with the low-level REST client from getting the artifact to using it in an application. 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /rest5-client/README.md: -------------------------------------------------------------------------------- 1 | # rest5-client 2 | 3 | The Elasticsearch Java client historically used a "Low Level Rest Client" (LLRC) based on Apache http client version 4 to handle http communications and distribution of requests among the nodes of a cluster. 4 | 5 | This directory is a port of this client to Apache http client version 5 that is mostly a drop-in replacement, except for the initialization phase. 6 | 7 | It is provided as an independent library as a convenience to users who have an existing code based on LLRC and would like to migrate to the more modern Apache http 5 library. 8 | -------------------------------------------------------------------------------- /docs/reference/external-resources.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/external-resources.html 4 | --- 5 | 6 | # External resources [external-resources] 7 | 8 | There is some material related to the Java API Client available outside this website that provides additional information or different perspectives on the library. 9 | 10 | You can find a community-maintained list of external resources in the [Java API Client GitHub repository](https://github.com/elastic/elasticsearch-java/tree/main/docs/external-resources.md). 11 | 12 | -------------------------------------------------------------------------------- /.github/workflows/checkstyle.yml: -------------------------------------------------------------------------------- 1 | name: Code style and license headers 2 | 3 | on: [pull_request] 4 | jobs: 5 | build: 6 | runs-on: ubuntu-latest 7 | strategy: 8 | matrix: 9 | java-version: [ 17 ] 10 | steps: 11 | - uses: actions/checkout@v2 12 | 13 | - name: Set up JDK ${{ matrix.java-version }} 14 | uses: actions/setup-java@v2 15 | with: 16 | java-version: ${{ matrix.java-version }} 17 | distribution: 'temurin' 18 | 19 | - name: Check style and license headers 20 | run: | 21 | ./gradlew checkstyleMain checkstyleTest 22 | -------------------------------------------------------------------------------- /examples/realworld-app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'org.springframework.boot' version '3.2.1' 4 | id 'io.spring.dependency-management' version '1.1.4' 5 | id 'application' 6 | } 7 | 8 | group = 'realworldapp' 9 | version = '0.0.1-SNAPSHOT' 10 | 11 | java { 12 | sourceCompatibility = '21' 13 | } 14 | 15 | repositories { 16 | mavenCentral() 17 | } 18 | 19 | dependencies { 20 | implementation('org.springframework.boot:spring-boot-starter-parent:3.2.0') 21 | implementation('realworldapp:rw-server') 22 | } 23 | 24 | mainClassName = 'rw-server/src/main/java/realworld/SpringBootApp.java' 25 | 26 | -------------------------------------------------------------------------------- /docs/reference/transport/rest5-client/index.md: -------------------------------------------------------------------------------- 1 | 2 | # REST 5 Client 3 | 4 | The low-level client’s features include: 5 | 6 | * minimal dependencies 7 | * load balancing across all available nodes 8 | * failover in case of node failures and upon specific response codes 9 | * failed connection penalization (whether a failed node is retried depends on how many consecutive times it failed; the more failed attempts the longer the client will wait before trying that same node again) 10 | * persistent connections 11 | * trace logging of requests and responses 12 | * optional automatic [discovery of cluster nodes](sniffer/index.md) 13 | 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build/ 3 | 4 | # Ignore Gradle GUI config 5 | gradle-app.setting 6 | 7 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 8 | !gradle-wrapper.jar 9 | 10 | # Cache of project 11 | .gradletasknamecache 12 | 13 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 14 | # gradle/wrapper/gradle-wrapper.properties 15 | 16 | # IntelliJ Idea 17 | .idea 18 | *.iml 19 | 20 | .ci/output 21 | 22 | # HTML files produced by the docs build 23 | html_docs 24 | 25 | # Local Makefile 26 | Makefile 27 | 28 | # Temp files and directories 29 | temp/ 30 | *Temp.java 31 | *TempTest.java 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: Feature Request 2 | description: Request a new feature 3 | labels: [] 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Please first search existing issues for the feature you are requesting. It may already exist, even as a closed issue. 9 | If it exists, please add a comment: along with subscribing you to the issue, this will help us prioritize features. 10 | - type: textarea 11 | id: description 12 | attributes: 13 | label: Description 14 | description: | 15 | Please give us as much context as possible about the feature. 16 | -------------------------------------------------------------------------------- /docs/reference/javadoc-source-code.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/java-client-javadoc.html 4 | --- 5 | 6 | # Javadoc and source code [java-client-javadoc] 7 | 8 | The Javadoc for the Java API Client is available at [https://artifacts.elastic.co/javadoc/co/elastic/clients/elasticsearch-java](https://artifacts.elastic.co/javadoc/co/elastic/clients/elasticsearch-java/{{version}}/index.html). 9 | 10 | The source code is at [https://github.com/elastic/elasticsearch-java/](https://github.com/elastic/elasticsearch-java/) and is licensed under the Apache 2.0 License. 11 | -------------------------------------------------------------------------------- /docs/reference/transport/rest-client/usage/javadoc.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/java-rest-low-javadoc.html 4 | navigation_title: Javadoc 5 | --- 6 | 7 | # Javadoc for the {{es}} Java REST client [java-rest-low-javadoc] 8 | 9 | :::{include} /reference/_snippets/legacy-rest-client.md 10 | ::: 11 | 12 | The javadoc for the low level REST client can be found at [https://snapshots.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-client/{{version}}/](https://snapshots.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-client/{{version}}/). 13 | 14 | -------------------------------------------------------------------------------- /docs/reference/transport/rest-client/sniffer/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/sniffer.html 4 | navigation_title: Sniffer 5 | --- 6 | 7 | # Sniffer in the {{es}} Java REST client[sniffer] 8 | 9 | :::{include} /reference/_snippets/legacy-rest-client.md 10 | ::: 11 | 12 | Minimal library that allows to automatically discover nodes from a running Elasticsearch cluster and set them to an existing `RestClient` instance. It retrieves by default the nodes that belong to the cluster using the Nodes Info api and uses jackson to parse the obtained json response. 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /docs/reference/transport/rest-client/sniffer/javadoc.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/java-rest-sniffer-javadoc.html 4 | navigation_title: Javadoc 5 | --- 6 | 7 | # Javadoc for the {{es}} Java REST client sniffer [java-rest-sniffer-javadoc] 8 | 9 | :::{include} /reference/_snippets/legacy-rest-client.md 10 | ::: 11 | 12 | The javadoc for the REST client sniffer can be found at [https://snapshots.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-client-sniffer/{{version}}/index.html](https://snapshots.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-client-sniffer/{{version}}/index.md). 13 | 14 | -------------------------------------------------------------------------------- /docs/reference/license.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/_license.html 4 | --- 5 | 6 | # License [_license] 7 | 8 | Copyright 2013-2019 Elasticsearch 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 11 | 12 | ``` 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | ``` 15 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 16 | 17 | -------------------------------------------------------------------------------- /docs/reference/transport/rest5-client/config/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | navigation_title: Common configuration 3 | --- 4 | 5 | # {{es}} Java REST 5 client configuration 6 | 7 | As explained in [Initialization](../usage/initialization.md), the `RestClientBuilder` supports providing both a `RequestConfigCallback` and an `HttpClientConfigCallback` which allow for any customization that the Apache Async Http Client exposes. Those callbacks make it possible to modify some specific behaviour of the client without overriding every other default configuration that the `Rest5Client` is initialized with. This section describes some common scenarios that require additional configuration for the low-level Java REST Client. 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /.github/workflows/issue-ingest-stats.yml: -------------------------------------------------------------------------------- 1 | name: 'Ingest Issue' 2 | 3 | on: 4 | issues: 5 | types: 6 | - opened 7 | - edited 8 | - closed 9 | - deleted 10 | - reopened 11 | - labeled 12 | - unlabeled 13 | 14 | concurrency: 15 | group: 'issue-stats-${{github.event.issue.id}}' 16 | cancel-in-progress: false 17 | 18 | jobs: 19 | issue: 20 | name: Ingest 21 | runs-on: ubuntu-latest 22 | steps: 23 | - name: Checkout 24 | uses: actions/checkout@v4 25 | 26 | - name: Ingest Issue 27 | uses: elastic/clients-team-automations/issues_stats@main 28 | with: 29 | issue_payload: ${{ toJSON(github.event.issue) }} 30 | es_cloud_id: ${{ vars.ES_CLOUD_ID }} 31 | es_api_key: ${{ secrets.ES_API_KEY }} 32 | -------------------------------------------------------------------------------- /examples/realworld-app/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | services: 2 | es: 3 | image: docker.elastic.co/elasticsearch/elasticsearch:8.11.1 4 | container_name: es 5 | environment: 6 | "discovery.type": "single-node" 7 | "xpack.security.enabled": "false" 8 | "xpack.security.http.ssl.enabled": "false" 9 | ports: 10 | - "9200:9200" 11 | networks: 12 | - elastic 13 | kibana: 14 | image: docker.elastic.co/kibana/kibana:8.7.1 15 | container_name: kibana 16 | environment: 17 | XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY: d1a66dfd-c4d3-4a0a-8290-2abcb83ab3aa 18 | ports: 19 | - 5601:5601 20 | networks: 21 | - elastic 22 | deploy: 23 | resources: 24 | limits: 25 | cpus: '2.0' 26 | reservations: 27 | cpus: '1.0' 28 | networks: 29 | elastic: 30 | -------------------------------------------------------------------------------- /docs/reference/api-conventions/method-naming.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/method-naming.html 4 | --- 5 | 6 | # Method naming conventions [method-naming] 7 | 8 | Classes in the Java API Client contain two kinds of methods and properties: 9 | 10 | * Methods and properties that are part of the API, such as `ElasticsearchClient.search()` or `SearchResponse.maxScore()`. They are derived from their respective names in the {{es}} JSON API using the standard Java `camelCaseNaming` convention. 11 | * Methods and properties that are part of the framework on which the Java API Client is built, such as `Query._kind()`. These methods and properties are prefixed with an underscore to both avoid any naming conflicts with API names, and as an easy way to distinguish the API from the framework. 12 | 13 | -------------------------------------------------------------------------------- /docs/reference/transport/rest-client/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/java-rest-low.html 4 | --- 5 | 6 | # Legacy REST Client [java-rest-low] 7 | 8 | :::{include} /reference/_snippets/legacy-rest-client.md 9 | ::: 10 | 11 | The low-level client’s features include: 12 | 13 | * minimal dependencies 14 | * load balancing across all available nodes 15 | * failover in case of node failures and upon specific response codes 16 | * failed connection penalization (whether a failed node is retried depends on how many consecutive times it failed; the more failed attempts the longer the client will wait before trying that same node again) 17 | * persistent connections 18 | * trace logging of requests and responses 19 | * optional automatic [discovery of cluster nodes](sniffer/index.md) 20 | 21 | -------------------------------------------------------------------------------- /rest5-client/src/test/resources/co/elastic/clients/transport/rest5_client/low_level/sniffer/es6_nodes_publication_address_format.json: -------------------------------------------------------------------------------- 1 | { 2 | "_nodes": { 3 | "total": 8, 4 | "successful": 8, 5 | "failed": 0 6 | }, 7 | "cluster_name": "elasticsearch", 8 | "nodes": { 9 | "ikXK_skVTfWkhONhldnbkw": { 10 | "name": "m1", 11 | "transport_address": "127.0.0.1:9300", 12 | "host": "127.0.0.1", 13 | "ip": "127.0.0.1", 14 | "version": "6.0.0", 15 | "build_hash": "8f0685b", 16 | "roles": [ 17 | "master", 18 | "ingest" 19 | ], 20 | "attributes": { }, 21 | "http": { 22 | "bound_address": [ 23 | "127.0.0.1:9200" 24 | ], 25 | "publish_address": "127.0.0.1:9200", 26 | "max_content_length_in_bytes": 104857600 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /docs/reference/transport/rest-client/usage/dependencies.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/java-rest-low-usage-dependencies.html 4 | --- 5 | 6 | # Dependencies [java-rest-low-usage-dependencies] 7 | 8 | :::{include} /reference/_snippets/legacy-rest-client.md 9 | ::: 10 | 11 | The low-level Java REST client internally uses the [Apache Http Async Client](https://hc.apache.org/httpcomponents-asyncclient-4.1.x/) to send http requests. It depends on the following artifacts, namely the async http client and its own transitive dependencies: 12 | 13 | * org.apache.httpcomponents:httpasyncclient 14 | * org.apache.httpcomponents:httpcore-nio 15 | * org.apache.httpcomponents:httpclient 16 | * org.apache.httpcomponents:httpcore 17 | * commons-codec:commons-codec 18 | * commons-logging:commons-logging 19 | 20 | -------------------------------------------------------------------------------- /.github/workflows/make-assemble.yml: -------------------------------------------------------------------------------- 1 | name: Assemble 2 | 3 | on: 4 | pull_request: 5 | paths-ignore: 6 | - 'README.md' 7 | push: 8 | paths-ignore: 9 | - 'README.md' 10 | branches: 11 | - main 12 | - master 13 | - '[0-9]+.[0-9]+' 14 | - '[0-9]+.x' 15 | 16 | jobs: 17 | assemble: 18 | name: Assemble 19 | runs-on: ubuntu-latest 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | stack_version: [ '8.0.0-SNAPSHOT'] 24 | 25 | steps: 26 | - name: Checkout 27 | uses: actions/checkout@v2 28 | - name: Set up JDK 11 29 | uses: actions/setup-java@v2 30 | with: 31 | java-version: '11' 32 | distribution: 'temurin' 33 | 34 | - run: "./.ci/make.sh assemble ${{ matrix.stack_version }}" 35 | name: Assemble ${{ matrix.stack_version }} 36 | -------------------------------------------------------------------------------- /docs/reference/api-conventions/exception-conventions.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/exception-conventions.html 4 | --- 5 | 6 | # Exceptions [exception-conventions] 7 | 8 | Client methods can throw two kinds of exceptions: 9 | 10 | * Requests that were received by the {{es}} server but that were rejected (validation error, server internal timeout exceeded, etc) will produce an `ElasticsearchException`. This exception contains details about the error, provided by {{es}}. 11 | * Requests that failed to reach the server (network error, server unavailable, etc) will produce a `TransportException`. That exception’s cause is the exception thrown by the lower-level implementation. In the case of the `RestClientTransport` it will be a `ResponseException` that contains the low level HTTP response. 12 | 13 | -------------------------------------------------------------------------------- /.buildkite/release_central.yml: -------------------------------------------------------------------------------- 1 | agents: 2 | provider: "gcp" 3 | 4 | steps: 5 | - label: ":java: :elasticsearch: Elasticsearch Java API client - Release" 6 | key: "release" 7 | command: ".ci/release_central.sh" 8 | artifact_paths: 9 | - ".ci/output/repository/**/*" 10 | - "signed-artifacts/**/*" 11 | - wait: ~ 12 | - label: "Publish S3 Artifacts :s3:" 13 | trigger: unified-release-publish-s3-artifacts 14 | key: publish-s3-service 15 | build: 16 | env: 17 | DESTINATION_PATH: "s3://artifacts.elastic.co/javadoc/co/elastic/clients/elasticsearch-java/" 18 | EXTRACT_ARTIFACT: "${VERSION}/elasticsearch-java-${VERSION}-javadoc.jar" 19 | 20 | #notify: 21 | # - slack: "#devtools-notify" 22 | # # skip slack messages if no failures and dry-run mode 23 | # if: 'build.state != "passed" && build.env("dry_run") == "false"' 24 | -------------------------------------------------------------------------------- /rest5-client/src/test/resources/co/elastic/clients/transport/rest5_client/low_level/sniffer/es7_nodes_publication_address_format.json: -------------------------------------------------------------------------------- 1 | { 2 | "_nodes": { 3 | "total": 8, 4 | "successful": 8, 5 | "failed": 0 6 | }, 7 | "cluster_name": "elasticsearch", 8 | "nodes": { 9 | "ikXK_skVTfWkhONhldnbkw": { 10 | "name": "m1", 11 | "transport_address": "127.0.0.1:9300", 12 | "host": "127.0.0.1", 13 | "ip": "127.0.0.1", 14 | "version": "6.0.0", 15 | "build_hash": "8f0685b", 16 | "roles": [ 17 | "master", 18 | "ingest" 19 | ], 20 | "attributes": { }, 21 | "http": { 22 | "bound_address": [ 23 | "elastic.test:9200" 24 | ], 25 | "publish_address": "elastic.test/127.0.0.1:9200", 26 | "max_content_length_in_bytes": 104857600 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /config/checkstyle/header.java.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | -------------------------------------------------------------------------------- /docs/reference/transport/rest5-client/config/number_of_threads.md: -------------------------------------------------------------------------------- 1 | --- 2 | navigation_title: Number of threads 3 | --- 4 | 5 | # Setting number of threads in the {{es}} Java REST 5 client 6 | 7 | The Apache Http Async Client starts by default one dispatcher thread, and a number of worker threads used by the connection manager, as many as the number of locally detected processors (depending on what `Runtime.getRuntime().availableProcessors()` returns). The number of threads can be modified as follows: 8 | 9 | % :::{include-code} src={{doc-tests-src}}/rest5_client/RestClientDocumentation.java tag=rest-client-config-threads 10 | ```java 11 | Rest5ClientBuilder builder = Rest5Client 12 | .builder(new HttpHost("localhost", 9200)) 13 | .setHttpClientConfigCallback(c -> c 14 | .setIOReactorConfig(IOReactorConfig.custom() 15 | .setIoThreadCount(1).build() 16 | ) 17 | ); 18 | ``` 19 | -------------------------------------------------------------------------------- /docs/release-notes/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | navigation_title: "Elasticsearch Java Client" 3 | mapped_pages: 4 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/release_notes.html 5 | --- 6 | 7 | # Elasticsearch Java Client release notes [elasticsearch-java-client-release-notes] 8 | 9 | Review the changes, fixes, and more in each version of Elasticsearch Java Client. 10 | 11 | To check for security updates, refer to [Security announcements for the Elastic stack](https://discuss.elastic.co/c/announcements/security-announcements/31). 12 | 13 | To check for issues, refer to [Known issues](../release-notes/known-issues.md). 14 | 15 | ## 9.2.0 16 | [Release notes](../release-notes/9-2-0.md) 17 | 18 | ## 9.1.0 19 | [Release notes](../release-notes/9-1-0.md) 20 | 21 | ## 9.0.4 22 | [Release notes](../release-notes/9-0-4.md) 23 | 24 | ## 9.0.0 25 | [Release notes](../release-notes/9-0-0.md) 26 | -------------------------------------------------------------------------------- /docs/reference/transport/rest-client/config/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/java-rest-low-config.html 4 | navigation_title: Common configuration 5 | --- 6 | 7 | # {{es}} Java REST client configuration [java-rest-low-config] 8 | 9 | :::{include} /reference/_snippets/legacy-rest-client.md 10 | ::: 11 | 12 | As explained in [Initialization](../usage/initialization.md), the `RestClientBuilder` supports providing both a `RequestConfigCallback` and an `HttpClientConfigCallback` which allow for any customization that the Apache Async Http Client exposes. Those callbacks make it possible to modify some specific behaviour of the client without overriding every other default configuration that the `RestClient` is initialized with. This section describes some common scenarios that require additional configuration for the low-level Java REST Client. 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /java-client/src/main/resources/co/elastic/clients/version.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to Elasticsearch B.V. under one or more contributor 3 | # license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright 5 | # ownership. Elasticsearch B.V. licenses this file to you under 6 | # the Apache License, Version 2.0 (the "License"); you may 7 | # not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | version=${version} 21 | git_revision=${git_revision} 22 | -------------------------------------------------------------------------------- /docs/reference/api-conventions/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/api-conventions.html 4 | --- 5 | 6 | # API conventions [api-conventions] 7 | 8 | The Java API Client uses a very consistent code structure, using modern code patterns that make complex requests easier to write and complex responses easier to process. The sections below explain these in details. 9 | 10 | * [Package structure and namespace clients](package-structure.md) 11 | * [Method naming conventions](method-naming.md) 12 | * [Blocking and asynchronous clients](blocking-async.md) 13 | * [Building API objects](building-objects.md) 14 | * [Lists and maps](lists-maps.md) 15 | * [Variant types](variant-types.md) 16 | * [Object life cycles and thread safety](object-lifecycles.md) 17 | * [Creating API objects from JSON data](loading-json.md) 18 | * [Exceptions](exception-conventions.md) 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | import java.nio.file.Paths 2 | 3 | /* 4 | * Licensed to Elasticsearch B.V. under one or more contributor 5 | * license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright 7 | * ownership. Elasticsearch B.V. licenses this file to you under 8 | * the Apache License, Version 2.0 (the "License"); you may 9 | * not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | rootProject.name = "elasticsearch-java" 23 | 24 | include("java-client") 25 | include("rest5-client") 26 | include("tools") 27 | -------------------------------------------------------------------------------- /docs/reference/transport/rest5-client/usage/logging.md: -------------------------------------------------------------------------------- 1 | --- 2 | navigation_title: Logging 3 | --- 4 | 5 | # Logging in the {{es}} Java REST 5 client 6 | 7 | The Java REST 5 client uses the same logging library that the Apache Async Http Client uses: [Apache Commons Logging](https://commons.apache.org/proper/commons-logging/), which comes with support for a number of popular logging implementations. The java packages to enable logging for is `co.elastic.clients.transport.rest5_client`. 8 | 9 | The request tracer logging can also be enabled to log every request and corresponding response in curl format. That comes handy when debugging, for instance in case a request needs to be manually executed to check whether it still yields the same response as it did. Enable trace logging for the `co.elastic.clients.transport.rest5_client.low_level.Request` class to have such log lines printed out. Do note that this type of logging is expensive and should not be enabled at all times in production environments, but rather temporarily used only when needed. 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.ci/release_central.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Licensed to Elasticsearch B.V. under one or more contributor 4 | # license agreements. See the NOTICE file distributed with 5 | # this work for additional information regarding copyright 6 | # ownership. Elasticsearch B.V. licenses this file to you under 7 | # the Apache License, Version 2.0 (the "License"); you may 8 | # not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # 20 | 21 | #see https://central.sonatype.org/publish/publish-gradle/#distributing-your-public-key 22 | 23 | set -euo pipefail 24 | 25 | .ci/configure_signing.sh 26 | 27 | .ci/make.sh release $VERSION 28 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/article/TagsDTO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.article; 21 | 22 | import java.util.List; 23 | 24 | public record TagsDTO(List tags) { 25 | } 26 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/utils/UserIdPair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.utils; 21 | 22 | import realworld.document.user.User; 23 | 24 | public record UserIdPair(User user, String id) { 25 | } 26 | -------------------------------------------------------------------------------- /java-client/src/main-flavored/java/co/elastic/clients/transport/VersionInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.transport; 21 | 22 | // Package private 23 | class VersionInfo { 24 | static final String VERSION = "9.3.0"; 25 | } 26 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/utils/ArticleIdPair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.utils; 21 | 22 | import realworld.document.article.Article; 23 | 24 | public record ArticleIdPair(Article article, String id) { 25 | } 26 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/comment/CommentsDTO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.comment; 21 | 22 | import java.util.List; 23 | 24 | public record CommentsDTO(List comments) { 25 | } 26 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/_helpers/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | /** 21 | * Base package for helpers providing additional helper/utilities on top of the Java API client. 22 | */ 23 | package co.elastic.clients.elasticsearch._helpers; 24 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/article/ArticlesDTO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.article; 21 | 22 | import java.util.List; 23 | 24 | public record ArticlesDTO(List articles, int articlesCount) { 25 | } 26 | -------------------------------------------------------------------------------- /java-client/src/test/java/co/elastic/clients/elasticsearch/experiments/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | /** 21 | * Experiments for the design of high-level client classes and usage illustration of the XContent-related classes. 22 | */ 23 | package co.elastic.clients.elasticsearch.experiments; 24 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/json/JsonpSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json; 21 | 22 | import jakarta.json.stream.JsonGenerator; 23 | 24 | public interface JsonpSerializer { 25 | void serialize(T value, JsonGenerator generator, JsonpMapper mapper); 26 | } 27 | -------------------------------------------------------------------------------- /docs/reference/transport/rest5-client/config/others.md: -------------------------------------------------------------------------------- 1 | --- 2 | navigation_title: More config options 3 | --- 4 | 5 | # Other configuration options in the {{es}} Java REST 5 client 6 | 7 | For any other required configuration needed, the Apache HttpAsyncClient docs should be consulted: [https://hc.apache.org/httpcomponents-client-5.5.x/](https://hc.apache.org/httpcomponents-client-5.5.x/) . 8 | 9 | ::::{note} 10 | If your application runs under the security manager you might be subject to the JVM default policies of caching positive hostname resolutions indefinitely and negative hostname resolutions for ten seconds. If the resolved addresses of the hosts to which you are connecting the client to vary with time then you might want to modify the default JVM behavior. These can be modified by adding [`networkaddress.cache.ttl=`](https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.md) and [`networkaddress.cache.negative.ttl=`](https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.md) to your [Java security policy](https://docs.oracle.com/javase/8/docs/technotes/guides/security/PolicyFiles.md). 11 | :::: 12 | 13 | 14 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/util/ObjectBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.util; 21 | 22 | /** 23 | * Base interface for all object builders. 24 | * 25 | * @param the type that will be built. 26 | */ 27 | public interface ObjectBuilder { 28 | T build(); 29 | } 30 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/transport/ResponseBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.transport; 21 | 22 | public abstract class ResponseBase { 23 | 24 | public abstract TransportInfo _transportInfo(); 25 | 26 | public abstract void _transportInfo(TransportInfo info); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /examples/esql-article/src/main/java/co/elastic/clients/esql/article/Book.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package co.elastic.clients.esql.article; 20 | 21 | public record Book( 22 | String title, 23 | String description, 24 | String author, 25 | Integer year, 26 | String publisher, 27 | Float ratings 28 | ) { 29 | } 30 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/_types/AcknowledgedResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch._types; 21 | 22 | /** 23 | * Base interface for responses that are acknowledged by the server 24 | */ 25 | public interface AcknowledgedResponse { 26 | boolean acknowledged(); 27 | } 28 | -------------------------------------------------------------------------------- /java-client/src/test/java/co/elastic/clients/elasticsearch/experiments/containers/SomeUnionVariant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch.experiments.containers; 21 | 22 | import co.elastic.clients.elasticsearch.experiments.UnionVariant; 23 | 24 | public interface SomeUnionVariant extends UnionVariant { 25 | } 26 | -------------------------------------------------------------------------------- /java-client/src/test/java/co/elastic/clients/elasticsearch/model/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | /** 21 | * Tests that verify correct types and serialization/deserialization of the API specification model using API 22 | * structures that cover the various model features 23 | */ 24 | package co.elastic.clients.elasticsearch.model; 25 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/exception/UnauthorizedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.exception; 21 | 22 | public class UnauthorizedException extends RuntimeException { 23 | 24 | public UnauthorizedException(String message) { 25 | super(message); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/util/ContentType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.util; 21 | 22 | /** 23 | * Constants for content-type values. 24 | */ 25 | public class ContentType { 26 | 27 | private ContentType() {} 28 | 29 | public static final String APPLICATION_JSON = "application/json"; 30 | } 31 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/constant/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.constant; 21 | 22 | public class Constants { 23 | 24 | public static final String ARTICLES = "articles"; 25 | public static final String USERS = "users"; 26 | public static final String COMMENTS = "comments"; 27 | } 28 | -------------------------------------------------------------------------------- /java-client/src/test/java/co/elastic/clients/elasticsearch/experiments/api/FooResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch.experiments.api; 21 | 22 | import co.elastic.clients.json.JsonpDeserializer; 23 | 24 | public class FooResponse { 25 | 26 | public static JsonpDeserializer PARSER = null; 27 | } 28 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/exception/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.exception; 21 | 22 | public class ResourceNotFoundException extends RuntimeException { 23 | 24 | public ResourceNotFoundException(String message) { 25 | super(message); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/exception/ResourceAlreadyExistsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.exception; 21 | 22 | public class ResourceAlreadyExistsException extends RuntimeException { 23 | 24 | public ResourceAlreadyExistsException(String message) { 25 | super(message); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/json/BufferingJsonpMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json; 21 | 22 | /** 23 | * A Jsonp mapper that has the additional capability of being able to buffer events. 24 | */ 25 | public interface BufferingJsonpMapper extends JsonpMapper { 26 | 27 | BufferingJsonGenerator createBufferingGenerator(); 28 | } 29 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/json/JsonpSerializable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json; 21 | 22 | import jakarta.json.stream.JsonGenerator; 23 | 24 | /** 25 | * An object that is its own JsonP serializer 26 | */ 27 | public interface JsonpSerializable { 28 | 29 | void serialize(JsonGenerator generator, JsonpMapper mapper); 30 | } 31 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/user/Author.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.user; 21 | 22 | public record Author(String username, String email, String bio, boolean following) { 23 | 24 | public Author(User user, boolean following) { 25 | this(user.username(), user.email(), user.bio(), following); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.transport; 21 | 22 | /** 23 | * A transport layer that implements Elasticsearch specificities. 24 | * 25 | * Currently an empty placeholder for future extension. 26 | */ 27 | public interface ElasticsearchTransport extends Transport { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /java-client/src/test/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.fasterxml.jackson.databind.ext; 21 | 22 | // A "duplicate" of a class that exists in the project's dependencies. 23 | // It's not actually used by the project, so the duplicate won't harm and is used in DuplicateResourceFinderTest 24 | public class CoreXMLSerializers { 25 | } 26 | -------------------------------------------------------------------------------- /examples/esql-article/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | plugins { 20 | id("java") 21 | } 22 | 23 | java { 24 | targetCompatibility = JavaVersion.VERSION_17 25 | } 26 | 27 | repositories { 28 | mavenCentral() 29 | } 30 | 31 | dependencies { 32 | implementation(project(":java-client")) 33 | implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.17.0") 34 | } 35 | -------------------------------------------------------------------------------- /rest5-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.transport.rest5_client.low_level; 21 | 22 | class Constants { 23 | // default buffer limit is 100MB 24 | public static final int DEFAULT_BUFFER_LIMIT = 100 * 1024 * 1024; 25 | public static final int DEFAULT_BUFFER_INITIAL_CAPACITY = 8192; 26 | } 27 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/user/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.user; 21 | 22 | import java.util.List; 23 | 24 | public record User( 25 | String username, 26 | String email, 27 | String password, 28 | String token, 29 | String bio, 30 | String image, 31 | byte[] salt, 32 | List following) { 33 | } 34 | -------------------------------------------------------------------------------- /java-client/src/test/java/co/elastic/clients/elasticsearch/experiments/UnionVariant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch.experiments; 21 | 22 | /** 23 | * An implementation of a variant type. 24 | */ 25 | public interface UnionVariant { 26 | 27 | /** 28 | * Get the type of this object when used as a variant 29 | */ 30 | Tag _variantType(); 31 | } 32 | -------------------------------------------------------------------------------- /docs/reference/api-conventions/package-structure.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/package-structure.html 4 | --- 5 | 6 | # Package structure and namespace clients [package-structure] 7 | 8 | The {{es}} API is large and is organized into feature groups, as can be seen in the [{{es}} API documentation](elasticsearch://reference/elasticsearch/rest-apis/index.md). 9 | 10 | The Java API Client follows this structure: feature groups are called “namespaces”, and each namespace is located in a subpackage of `co.elastic.clients.elasticsearch`. 11 | 12 | Each of the namespace clients can be accessed from the top level {{es}} client. The only exceptions are the “search” and “document” APIs which are located in the `core` subpackage and can be accessed on the main {{es}} client object. 13 | 14 | The snippet below shows how to use the indices namespace client to create an index (the lambda syntax is explained in [Building API objects](building-objects.md)): 15 | 16 | ```java 17 | // Create the "products" index 18 | ElasticsearchClient client = ... 19 | client.indices().create(c -> c.index("products")); 20 | ``` 21 | 22 | Namespace clients are very lightweight objects that can be created on the fly. 23 | 24 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/json/JsonBuffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json; 21 | 22 | import jakarta.json.stream.JsonParser; 23 | 24 | /** 25 | * A buffer of JSON events. 26 | */ 27 | public interface JsonBuffer { 28 | 29 | /** 30 | * Get the contents of this buffer as a JSON parser. Can be called multiple times. 31 | */ 32 | JsonParser asParser(); 33 | } 34 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/json/jackson/Jackson3Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json.jackson; 21 | 22 | import jakarta.json.JsonException; 23 | import tools.jackson.core.JacksonException; 24 | 25 | class Jackson3Utils { 26 | public static JsonException convertException(JacksonException je) { 27 | return new JsonException("Jackson exception", je); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /docs/reference/transport/rest-client/config/number_of_threads.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/_number_of_threads.html 4 | navigation_title: Number of threads 5 | --- 6 | 7 | # Setting number of threads in the {{es}} Java REST client [_number_of_threads] 8 | 9 | :::{include} /reference/_snippets/legacy-rest-client.md 10 | ::: 11 | 12 | The Apache Http Async Client starts by default one dispatcher thread, and a number of worker threads used by the connection manager, as many as the number of locally detected processors (depending on what `Runtime.getRuntime().availableProcessors()` returns). The number of threads can be modified as follows: 13 | 14 | ```java 15 | RestClientBuilder builder = RestClient.builder( 16 | new HttpHost("localhost", 9200)) 17 | .setHttpClientConfigCallback(new HttpClientConfigCallback() { 18 | @Override 19 | public HttpAsyncClientBuilder customizeHttpClient( 20 | HttpAsyncClientBuilder httpClientBuilder) { 21 | return httpClientBuilder.setDefaultIOReactorConfig( 22 | IOReactorConfig.custom() 23 | .setIoThreadCount(1) 24 | .build()); 25 | } 26 | }); 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/json/BufferingJsonParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json; 21 | 22 | import jakarta.json.stream.JsonParser; 23 | 24 | public interface BufferingJsonParser extends JsonParser { 25 | 26 | /** 27 | * Get the value at the current parser position as a JsonData object. 28 | * @return 29 | */ 30 | JsonData getJsonData(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /example-transports/src/test/java/co/elastic/clients/transport/netty/NettyClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.transport.netty; 21 | 22 | 23 | import co.elastic.clients.transport.TransportHttpClientTest; 24 | 25 | public class NettyClientTest extends TransportHttpClientTest { 26 | 27 | public NettyClientTest() throws Exception { 28 | super(new NettyTransportHttpClient()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /java-client/src/test/java/co/elastic/clients/transport/VersionInfoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.transport; 21 | 22 | import org.junit.jupiter.api.Assertions; 23 | import org.junit.jupiter.api.Test; 24 | 25 | public class VersionInfoTest { 26 | 27 | @Test 28 | public void testClientMeta() { 29 | String version = VersionInfo.VERSION; 30 | Assertions.assertTrue(ElasticsearchTransportBase.getClientMeta().startsWith("es=" + version + ",jv=")); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /docs/reference/transport/rest-client/config/others.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/_others.html 4 | navigation_title: More config options 5 | --- 6 | 7 | # Other configuration options in the {{es}} Java REST client [_others] 8 | 9 | :::{include} /reference/_snippets/legacy-rest-client.md 10 | ::: 11 | 12 | For any other required configuration needed, the Apache HttpAsyncClient docs should be consulted: [https://hc.apache.org/httpcomponents-asyncclient-4.1.x/](https://hc.apache.org/httpcomponents-asyncclient-4.1.x/) . 13 | 14 | ::::{note} 15 | If your application runs under the security manager you might be subject to the JVM default policies of caching positive hostname resolutions indefinitely and negative hostname resolutions for ten seconds. If the resolved addresses of the hosts to which you are connecting the client to vary with time then you might want to modify the default JVM behavior. These can be modified by adding [`networkaddress.cache.ttl=`](https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.md) and [`networkaddress.cache.negative.ttl=`](https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.md) to your [Java security policy](https://docs.oracle.com/javase/8/docs/technotes/guides/security/PolicyFiles.md). 16 | :::: 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/user/LoginDTO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.user; 21 | 22 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 23 | import com.fasterxml.jackson.annotation.JsonTypeName; 24 | import jakarta.validation.constraints.NotNull; 25 | 26 | @JsonTypeName("user") 27 | @JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME) 28 | public record LoginDTO(@NotNull String email, @NotNull String password) { 29 | } 30 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/transport/TransportInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.transport; 21 | 22 | import java.util.List; 23 | 24 | public interface TransportInfo { 25 | 26 | String requestUrl(); 27 | byte[] requestBody(); 28 | String requestBodyText(); 29 | // request headers 30 | 31 | int responseStatusCode(); 32 | byte[] responseBody(); 33 | String responseBodyText(); 34 | // response headers 35 | 36 | List warnings(); 37 | } 38 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/transport/JsonEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.transport; 21 | 22 | import co.elastic.clients.json.JsonpDeserializer; 23 | 24 | /** 25 | * An endpoint with a JSON response body. 26 | */ 27 | public interface JsonEndpoint extends Endpoint { 28 | 29 | /** 30 | * The entity parser for the response body. 31 | */ 32 | JsonpDeserializer responseDeserializer(); 33 | } 34 | -------------------------------------------------------------------------------- /docs/reference/usage/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/usage.html 4 | --- 5 | 6 | # Using the Java API client [usage] 7 | 8 | The sections below provide tutorials on the most frequently used and some less obvious features of {{es}}. 9 | 10 | For a full reference, see the [Elasticsearch documentation](docs-content://get-started/index.md) and in particular the [REST APIs](elasticsearch://reference/elasticsearch/rest-apis/index.md) section. The Java API Client follows closely the JSON structures described there, using the [Java API conventions](/reference/api-conventions/index.md). 11 | 12 | If you’re new to Elasticsearch, make sure also to read [Elasticsearch’s quick start](docs-content://solutions/search/get-started.md) that provides a good introduction. 13 | 14 | * [ES|QL in the Java client](/reference/usage/esql.md) 15 | * [Indexing single documents](/reference/usage/indexing.md) 16 | * [Bulk: indexing multiple documents](/reference/usage/indexing-bulk.md) 17 | * [Reading documents by id](/reference/usage/reading.md) 18 | * [Searching for documents](/reference/usage/searching.md) 19 | * [Aggregations](/reference/usage/aggregations.md) 20 | 21 | ::::{note} 22 | This is still a work in progress, more sections will be added in the near future. 23 | :::: 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/user/RegisterDTO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.user; 21 | 22 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 23 | import com.fasterxml.jackson.annotation.JsonTypeName; 24 | import jakarta.validation.constraints.NotNull; 25 | 26 | @JsonTypeName("user") 27 | @JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME) 28 | public record RegisterDTO(@NotNull String username, @NotNull String email, @NotNull String password) { 29 | } 30 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-rest/src/main/java/realworld/rest/error/RestError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.rest.error; 21 | 22 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 23 | import com.fasterxml.jackson.annotation.JsonTypeInfo.As; 24 | import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; 25 | import com.fasterxml.jackson.annotation.JsonTypeName; 26 | 27 | import java.util.List; 28 | 29 | @JsonTypeName("errors") 30 | @JsonTypeInfo(include = As.WRAPPER_OBJECT, use = Id.NAME) 31 | public record RestError(List body) { 32 | } 33 | 34 | -------------------------------------------------------------------------------- /rest5-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/sniffer/NodesSniffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package co.elastic.clients.transport.rest5_client.low_level.sniffer; 20 | 21 | import co.elastic.clients.transport.rest5_client.low_level.Node; 22 | 23 | import java.io.IOException; 24 | import java.util.List; 25 | 26 | /** 27 | * Responsible for sniffing the http hosts 28 | */ 29 | public interface NodesSniffer { 30 | /** 31 | * Returns the sniffed Elasticsearch nodes. 32 | */ 33 | List sniff() throws IOException; 34 | } 35 | -------------------------------------------------------------------------------- /docs/reference/api-conventions/object-lifecycles.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/object-lifecycles.html 4 | --- 5 | 6 | # Object life cycles and thread safety [object-lifecycles] 7 | 8 | There are five kinds of objects in the Java API Client with different life cycles: 9 | 10 | **Object mapper** 11 | : Stateless and thread-safe, but can be costly to create. It’s usually a singleton that is created at application startup and used to create the transport. 12 | 13 | **Transport** 14 | : Thread-safe, holds network resources through the underlying HTTP client. A transport object is associated with an {{es}} cluster and has to be explicitly closed to release the underlying resources such as network connections. 15 | 16 | **Clients** 17 | : Immutable, stateless and thread-safe. These are very lightweight objects that just wrap a transport and provide API endpoints as methods. Closing a client closes the underlying transport. 18 | 19 | **Builders** 20 | : Mutable, non thread-safe. Builders are transient objects that should not be reused after calling `build()`. 21 | 22 | **Requests & other API objects** 23 | : Immutable, thread-safe. If your application uses the same request or same parts of a request over and over, these objects can be prepared in advance and reused across multiple calls over multiple clients with different transports. 24 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/article/ArticleUpdateDTO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.article; 21 | 22 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 23 | import com.fasterxml.jackson.annotation.JsonTypeInfo.As; 24 | import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; 25 | import com.fasterxml.jackson.annotation.JsonTypeName; 26 | 27 | @JsonTypeName("article") 28 | @JsonTypeInfo(include = As.WRAPPER_OBJECT, use = Id.NAME) 29 | public record ArticleUpdateDTO(String title, String description, String body) { 30 | } 31 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/transport/endpoints/BooleanResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.transport.endpoints; 21 | 22 | /** 23 | * An API response that has boolean value according to the HTTP status code. 24 | * Typically status codes 1xx, 2xx and 3xx are "true" and 4xx is false. 25 | */ 26 | public class BooleanResponse { 27 | private final boolean value; 28 | 29 | public BooleanResponse(boolean value) { 30 | this.value = value; 31 | } 32 | 33 | public boolean value() { 34 | return value; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /java-client/src/test/resources/co/elastic/clients/elasticsearch/spec_issues/issue-0107-response.json: -------------------------------------------------------------------------------- 1 | { 2 | "took" : 1, 3 | "timed_out" : false, 4 | "_shards" : { 5 | "total" : 1, 6 | "successful" : 1, 7 | "skipped" : 0, 8 | "failed" : 0 9 | }, 10 | "hits" : { 11 | "total" : { 12 | "value" : 5, 13 | "relation" : "eq" 14 | }, 15 | "max_score" : null, 16 | "hits" : [ ] 17 | }, 18 | "aggregations": { 19 | "date_range#date_ranges": { 20 | "buckets": [ 21 | { 22 | "key": "2Wk", 23 | "from": 1.6408224E12, 24 | "from_as_string": "2021-12-30T00:00:00.000Z", 25 | "to": 1.642032E12, 26 | "to_as_string": "2022-01-06T00:00:00.000Z", 27 | "doc_count": 0, 28 | "avg#avgCost": { 29 | "value": null 30 | }, 31 | "cardinality#uniqueUsers": { 32 | "value": 0 33 | } 34 | }, 35 | { 36 | "key": "1Wk", 37 | "from": 1.6414272E12, 38 | "from_as_string": "2022-01-06T00:00:00.000Z", 39 | "to": 1.642032E12, 40 | "to_as_string": "2022-01-13T00:00:00.000Z", 41 | "doc_count": 0, 42 | "avg#avgCost": { 43 | "value": null 44 | }, 45 | "cardinality#uniqueUsers": { 46 | "value": 0 47 | } 48 | } 49 | ] 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'org.springframework.boot' version '3.2.1' 4 | id 'io.spring.dependency-management' version '1.1.4' 5 | } 6 | 7 | group = 'realworldapp' 8 | version = '0.0.1-SNAPSHOT' 9 | 10 | java { 11 | sourceCompatibility = '21' 12 | } 13 | 14 | repositories { 15 | mavenCentral() 16 | } 17 | 18 | 19 | dependencies { 20 | // Spring 21 | implementation('org.springframework.boot:spring-boot-starter:3.2.0') 22 | implementation('org.springframework.boot:spring-boot-starter-validation:3.2.0') 23 | 24 | // Elastic 25 | implementation('co.elastic.clients:elasticsearch-java:8.11.4') 26 | implementation('com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.16.0') 27 | 28 | // JWT creation + parsing 29 | implementation('javax.xml.bind:jaxb-api:2.3.1') 30 | implementation('io.jsonwebtoken:jjwt:0.9.1') 31 | 32 | // Slug 33 | implementation('com.github.slugify:slugify:3.0.6') 34 | 35 | // MIT 36 | // https://www.testcontainers.org/ 37 | testImplementation('org.testcontainers:testcontainers:1.17.3') 38 | testImplementation('org.testcontainers:elasticsearch:1.17.3') 39 | // updating transitive dependency from testcontainers 40 | testImplementation("org.apache.commons:commons-compress:1.26.1") 41 | 42 | 43 | testImplementation('org.springframework.boot:spring-boot-starter-test:3.2.0') 44 | } 45 | 46 | tasks.named('test') { 47 | useJUnitPlatform() 48 | } 49 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/comment/CommentCreationDTO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.comment; 21 | 22 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 23 | import com.fasterxml.jackson.annotation.JsonTypeInfo.As; 24 | import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; 25 | import com.fasterxml.jackson.annotation.JsonTypeName; 26 | import jakarta.validation.constraints.NotNull; 27 | 28 | @JsonTypeName("comment") 29 | @JsonTypeInfo(include = As.WRAPPER_OBJECT, use = Id.NAME) 30 | public record CommentCreationDTO(@NotNull String body) { 31 | } 32 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-server/src/main/java/realworld/SpringBootApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld; 21 | 22 | import org.springframework.boot.SpringApplication; 23 | import org.springframework.boot.autoconfigure.SpringBootApplication; 24 | import realworld.config.DefaultProperties; 25 | 26 | @SpringBootApplication 27 | public class SpringBootApp { 28 | 29 | public static void main(String[] args) { 30 | SpringApplication app = new SpringApplication(SpringBootApp.class); 31 | app.setDefaultProperties(DefaultProperties.getDefaultProperties()); 32 | app.run(args); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/json/BufferingJsonGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json; 21 | 22 | import jakarta.json.stream.JsonGenerator; 23 | import jakarta.json.stream.JsonParser; 24 | 25 | public interface BufferingJsonGenerator extends JsonGenerator { 26 | 27 | /** 28 | * Close this generator and return the buffered content. 29 | */ 30 | JsonData getJsonData(); 31 | 32 | /** 33 | * Close this generator and return the buffered content as a parser. 34 | */ 35 | JsonParser getParser(); 36 | 37 | void copyValue(JsonParser parser); 38 | } 39 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/util/OpenTaggedUnion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.util; 21 | 22 | import javax.annotation.Nullable; 23 | 24 | /** 25 | * A union that is open, i.e. non-exhaustive, where new variants can be defined on the server using extension plugins. 26 | * 27 | * @see TaggedUnion 28 | */ 29 | public interface OpenTaggedUnion, BaseType> extends TaggedUnion { 30 | 31 | /** 32 | * Get the actual kind when {@code _kind()} equals {@code _Custom} (plugin-defined variant). 33 | */ 34 | @Nullable 35 | String _customKind(); 36 | } 37 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug.yml: -------------------------------------------------------------------------------- 1 | name: Bug 2 | description: "Report a bug." 3 | labels: [] 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Github is reserved for bug reports and feature requests. If you have a question or 9 | an unconfirmed bug, please visit the [forums](https://discuss.elastic.co/tag/language-clients). 10 | 11 | Please fill in the following details to help us reproduce the bug: 12 | 13 | - type: input 14 | id: client_version 15 | attributes: 16 | label: Java API client version 17 | description: The version of Java API client 18 | validations: 19 | required: true 20 | 21 | - type: input 22 | id: java_version 23 | attributes: 24 | label: Java version 25 | description: The Java version used with the Java API client 26 | validations: 27 | required: true 28 | 29 | - type: input 30 | id: es_version 31 | attributes: 32 | label: Elasticsearch Version 33 | description: The version of Elasticsearch you are using with the Java API client 34 | validations: 35 | required: true 36 | 37 | - type: textarea 38 | id: problem 39 | attributes: 40 | label: Problem description 41 | description: | 42 | A description of the problem including expected versus actual behavior. Providing JSON snippets of the expected behavior from the 43 | Kibana dev tools console will help diagnosing the issue. 44 | validations: 45 | required: true 46 | 47 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/comment/Comment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.comment; 21 | 22 | import com.fasterxml.jackson.annotation.JsonFormat; 23 | import realworld.document.user.Author; 24 | 25 | import java.time.Instant; 26 | 27 | public record Comment( 28 | Long id, 29 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", timezone = "UTC") 30 | Instant createdAt, 31 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", timezone = "UTC") 32 | Instant updatedAt, 33 | String body, 34 | Author author, 35 | String articleSlug) { 36 | } 37 | -------------------------------------------------------------------------------- /java-client/src/test/resources/co/elastic/clients/elasticsearch/spec_issues/issue-0057-response.json: -------------------------------------------------------------------------------- 1 | { 2 | "took": 67, 3 | "timed_out": false, 4 | "_shards": { 5 | "total": 1, 6 | "successful": 1, 7 | "skipped": 0, 8 | "failed": 0 9 | }, 10 | "hits": { 11 | "total": { 12 | "value": 0, 13 | "relation": "eq" 14 | }, 15 | "max_score": null, 16 | "hits": [] 17 | }, 18 | "suggest": { 19 | "completion#completion:completion1": [ 20 | { 21 | "text": "hash", 22 | "offset": 0, 23 | "length": 4, 24 | "options": [ 25 | { 26 | "text": "HashMap-Complete1", 27 | "_index": "document", 28 | "_id": "2", 29 | "_score": 1.0 30 | }, 31 | { 32 | "text": "HashSet-Complete1", 33 | "_index": "document", 34 | "_id": "1", 35 | "_score": 1.0 36 | } 37 | ] 38 | } 39 | ], 40 | "completion#completion:completion2": [ 41 | { 42 | "text": "hash", 43 | "offset": 0, 44 | "length": 4, 45 | "options": [ 46 | { 47 | "text": "HashMap-Complete2", 48 | "_index": "document", 49 | "_id": "2", 50 | "_score": 1.0 51 | }, 52 | { 53 | "text": "HashSet-Complete2", 54 | "_index": "document", 55 | "_id": "1", 56 | "_score": 1.0 57 | } 58 | ] 59 | } 60 | ] 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-server/src/main/java/realworld/config/DefaultProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.config; 21 | 22 | import java.util.Properties; 23 | 24 | public class DefaultProperties { 25 | 26 | private DefaultProperties() { 27 | } 28 | 29 | public static Properties getDefaultProperties() { 30 | Properties p = new Properties(); 31 | p.setProperty("server.address", "0.0.0.0"); 32 | p.setProperty("server.port", "8080"); 33 | p.setProperty("server.scheme", "http"); 34 | p.setProperty("server.servlet.context-path", "/api"); 35 | p.setProperty("spring.output.ansi.enabled", "ALWAYS"); 36 | return p; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/util/AllowForbiddenApis.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.util; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | /** 28 | * Annotation to allow usage of forbidden APIs inside a whole class, a method, or a field. 29 | */ 30 | @Retention(RetentionPolicy.CLASS) 31 | @Target({ ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE }) 32 | public @interface AllowForbiddenApis { 33 | /** 34 | * The reason for allowing forbidden APIs 35 | */ 36 | String value(); 37 | } 38 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/user/Profile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.user; 21 | 22 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 23 | import com.fasterxml.jackson.annotation.JsonTypeInfo.As; 24 | import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; 25 | import com.fasterxml.jackson.annotation.JsonTypeName; 26 | 27 | @JsonTypeName("profile") 28 | @JsonTypeInfo(include = As.WRAPPER_OBJECT, use = Id.NAME) 29 | public record Profile(String username, String image, String bio, boolean following) { 30 | 31 | public Profile(User user, boolean following) { 32 | this(user.username(), user.image(), user.bio(), following); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /java-client/src/test/java/co/elastic/clients/elasticsearch/experiments/base/PrimitiveUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch.experiments.base; 21 | 22 | /** 23 | * Support functions for primitive fields in generated classes 24 | */ 25 | public class PrimitiveUtils { 26 | public static int checkedValue(int value, boolean isSet) { 27 | mustBeSet(isSet); 28 | return value; 29 | } 30 | 31 | public static long checkedValue(long value, boolean isSet) { 32 | mustBeSet(isSet); 33 | return value; 34 | } 35 | 36 | private static void mustBeSet(boolean isSet) { 37 | if (!isSet) { 38 | throw new IllegalStateException("Value is not set"); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /docs/release-notes/9-0-4.md: -------------------------------------------------------------------------------- 1 | --- 2 | navigation_title: "9.0.4" 3 | --- 4 | # Elasticsearch Java Client 9.0.4 [elasticsearch-java-client-904] 5 | 6 | Discover what changed in the 9.0.4 version of the Java client. 7 | 8 | ## Breaking changes [elasticsearch-java-client-904-breaking-changes] 9 | 10 | There are no breaking changes in this version of the client. 11 | 12 | ## Features and enhancements [elasticsearch-java-client-904-features-enhancements] 13 | 14 | ### Added callbacks to Rest5ClientBuilder 15 | `Rest5ClientBuilder` now has the same level of in-depth configuration as the legacy `RestClientBuilder`, allowing you to customize the underlying Apache `HttpClient` through callback functions. For example, here's how to configure the `IOReactor` thread count: 16 | ```java 17 | Rest5ClientBuilder builder = Rest5Client 18 | .builder(new HttpHost("localhost", 9200)) 19 | .setHttpClientConfigCallback(c -> c 20 | .setIOReactorConfig(IOReactorConfig.custom() 21 | .setIoThreadCount(1).build() 22 | ) 23 | ); 24 | ``` 25 | Here's how to customize the response timeout: 26 | ```java 27 | Rest5ClientBuilder builder = Rest5Client 28 | .builder(new HttpHost("localhost", 9200)) 29 | .setRequestConfigCallback(r -> r 30 | .setConnectTimeout(Timeout.of(5000, TimeUnit.MILLISECONDS)) 31 | .setResponseTimeout(Timeout.of(30000, TimeUnit.MILLISECONDS)) 32 | .build() 33 | ); 34 | ``` 35 | :::: 36 | 37 | ## Deprecations [elasticsearch-java-client-904-deprecations] 38 | 39 | Nothing was deprecated in this version of the client. 40 | -------------------------------------------------------------------------------- /docs/reference/api-conventions/blocking-async.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/blocking-and-async.html 4 | --- 5 | 6 | # Blocking and asynchronous clients [blocking-and-async] 7 | 8 | API clients come in two flavors: blocking and asynchronous. All methods on asynchronous clients return a standard `CompletableFuture`. 9 | 10 | Both flavors can be used at the same time depending on your needs, sharing the same transport object: 11 | 12 | % :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=blocking-and-async 13 | ```java 14 | // Synchronous blocking client 15 | ElasticsearchClient esClient = new ElasticsearchClient(transport); 16 | 17 | if (esClient.exists(b -> b.index("products").id("foo")).value()) { 18 | logger.info("product exists"); 19 | } 20 | 21 | // Asynchronous non-blocking client 22 | ElasticsearchAsyncClient asyncClient = 23 | new ElasticsearchAsyncClient(transport); 24 | 25 | asyncClient 26 | .exists(b -> b.index("products").id("foo")) 27 | .whenComplete((response, exception) -> { 28 | if (exception != null) { 29 | logger.error("Failed to index", exception); 30 | } else { 31 | logger.info("Product exists"); 32 | } 33 | }); 34 | ``` 35 | 36 | Although we won’t go in deeper details on asynchronous programming in Java, remember to handle failures of asynchronous tasks. It’s easy to overlook them and have errors go unnoticed. 37 | 38 | :::{include} /reference/_snippets/doc-tests-blurb.md 39 | ::: 40 | 41 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/json/NdJsonpSerializable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json; 21 | 22 | import java.util.Iterator; 23 | 24 | /** 25 | * Marks a class a being serialized as nd-json (e.g. bulk requests). 26 | *

27 | * If an item returned by the iterator implements {@link NdJsonpSerializable}, it should also be output as nd-json. 28 | * This allows flattening nested structures (e.g. a bulk index operation and its document). However, if this object returns itself 29 | * as part of the iterator values, it then has to be serialized and not flattened again (which would lead to an infinite loop). 30 | */ 31 | public interface NdJsonpSerializable { 32 | Iterator _serializables(); 33 | } 34 | -------------------------------------------------------------------------------- /rest5-client/src/test/java/co/elastic/clients/transport/rest5_client/low_level/sniffer/MockNodesSniffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.transport.rest5_client.low_level.sniffer; 21 | 22 | import co.elastic.clients.transport.rest5_client.low_level.Node; 23 | import org.apache.hc.core5.http.HttpHost; 24 | 25 | import java.util.Collections; 26 | import java.util.List; 27 | 28 | /** 29 | * Mock implementation of {@link NodesSniffer}. Useful to prevent any connection attempt while testing builders etc. 30 | */ 31 | class MockNodesSniffer implements NodesSniffer { 32 | @Override 33 | public List sniff() { 34 | return Collections.singletonList(new Node(new HttpHost("localhost", 9200))); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/json/JsonpMapperFeatures.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json; 21 | 22 | /** 23 | * Defines attribute names for {@link JsonpMapper} features. 24 | */ 25 | public class JsonpMapperFeatures { 26 | 27 | /** 28 | * 29 | */ 30 | public static final String SERIALIZE_TYPED_KEYS = JsonpMapperFeatures.class.getName() + ":SERIALIZE_TYPED_KEYS"; 31 | 32 | /** 33 | * Disables custom variants in union types (false by default). Used in tests to avoid interpreting wrong variant kinds as a custom 34 | * extension. 35 | */ 36 | public static final String FORBID_CUSTOM_VARIANTS = JsonpMapperFeatures.class.getName() + ":FORBID_CUSTOM_VARIANTS"; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/article/ArticleCreationDTO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.article; 21 | 22 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 23 | import com.fasterxml.jackson.annotation.JsonTypeInfo.As; 24 | import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; 25 | import com.fasterxml.jackson.annotation.JsonTypeName; 26 | import jakarta.validation.constraints.NotNull; 27 | 28 | import java.util.List; 29 | 30 | @JsonTypeName("article") 31 | @JsonTypeInfo(include = As.WRAPPER_OBJECT, use = Id.NAME) 32 | public record ArticleCreationDTO(@NotNull String title, @NotNull String description, @NotNull String body, 33 | List tagList) { 34 | } 35 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/_helpers/esql/jdbc/JdbcWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch._helpers.esql.jdbc; 21 | 22 | import java.sql.SQLException; 23 | import java.sql.Wrapper; 24 | 25 | interface JdbcWrapper extends Wrapper { 26 | 27 | @Override 28 | default boolean isWrapperFor(Class iface) throws SQLException { 29 | return iface != null && iface.isAssignableFrom(getClass()); 30 | } 31 | 32 | @SuppressWarnings("unchecked") 33 | @Override 34 | default T unwrap(Class iface) throws SQLException { 35 | if (isWrapperFor(iface)) { 36 | return (T) this; 37 | } 38 | throw new SQLException(); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /docs/external-resources.md: -------------------------------------------------------------------------------- 1 | # External resources 2 | 3 | 8 | 9 | This page aggregates links to material related to the Java API client that provide additional information or different perspectives on the library. [Contributions are welcome](https://github.com/elastic/elasticsearch-java/issues/new?title=New+external+resource). 10 | 11 | **Disclaimer**: These links are being provided for informational purposes; they do not constitute an endorsement or an approval by Elastic. Please [let us know](https://github.com/elastic/elasticsearch-java/issues/new?title=Issue+in+external+resources) about links that you think are outdated or inappropriate. 12 | 13 | * [ElasticCC platform - Part 2 - Using the new Elasticsearch Java Client](https://spinscale.de/posts/2022-03-03-running-the-elasticcc-platform-part-2.html) 14 | *Blog post, March 2022* 15 | 16 | 17 | * The new Elasticsearch Java Client: getting started and behind the scenes - [Video](https://www.youtube.com/watch?v=61MQoSFt2j0&list=PL_mJOmq4zsHbigQnsjEcWed6N7Do5kss_&index=12), [Slides](https://docs.google.com/presentation/d/1R9pLrRdIPQplNr23TTqST-892Un9g_3AmrLjG5lNM74/present) 18 | *Presentation at the Elastic Community Conference, Feb 2022* 19 | 20 | 21 | * [GitHub Code Sample Repo](https://github.com/spinscale/elasticsearch-rest-client-samples) on how to use and test the new Elasticsearch Java Client 22 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/user/UserDTO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.user; 21 | 22 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 23 | import com.fasterxml.jackson.annotation.JsonTypeInfo.As; 24 | import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; 25 | import com.fasterxml.jackson.annotation.JsonTypeName; 26 | 27 | @JsonTypeName("user") 28 | @JsonTypeInfo(include = As.WRAPPER_OBJECT, use = Id.NAME) 29 | public record UserDTO( 30 | String username, 31 | String email, 32 | String token, 33 | String bio, 34 | String image) { 35 | 36 | public UserDTO(User user) { 37 | this(user.username(), user.email(), user.token(), user.bio(), user.image()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /rest5-client/src/test/resources/co/elastic/clients/transport/rest5_client/low_level/test.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEATCCAumgAwIBAgIEObhDZDANBgkqhkiG9w0BAQsFADBnMQswCQYDVQQGEwJV 3 | UzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDU1vdW50YWluIFZpZXcxEDAOBgNVBAoT 4 | B2VsYXN0aWMxDTALBgNVBAsTBHRlc3QxEjAQBgNVBAMTCXRlc3Qgbm9kZTAeFw0x 5 | NzA3MTcxNjEyNTZaFw0yNzA3MTUxNjEyNTZaMGcxCzAJBgNVBAYTAlVTMQswCQYD 6 | VQQIEwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHZWxhc3Rp 7 | YzENMAsGA1UECxMEdGVzdDESMBAGA1UEAxMJdGVzdCBub2RlMIIBIjANBgkqhkiG 8 | 9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnXtuGIgAq6vWzUD34HXkYF+0u103hb8d1h35 9 | kjeuNApkUhS6x/VbuNp7TpWmprfDgG5w9TourHvyiqcQMDEWrBunS6rmKo1jK1Wm 10 | le3qA3F2l9VIZSNeeYQgezmzuElEPPmBjN8XBByIWKYjZcGd5u7DiquPUh9QLIev 11 | itgB2jfi9D8ewyvaSbVAQuQwyIaDN9L74wKyMC8EuzzAWNSDjgIhhwcR5qg17msa 12 | ItyM44/3hik+ObIGpMlLSxQu2V1U9bOaq48JjQBLHVg1vzC9VzGuNdEb8haFnhJN 13 | UrdESdHymbtBSUvy30iB+kHq5R8wQ4pC+WxChQnbA2GskuFrMQIDAQABo4G0MIGx 14 | MIGPBgNVHREEgYcwgYSHBH8AAAGHEAAAAAAAAAAAAAAAAAAAAAGCCWxvY2FsaG9z 15 | dIIVbG9jYWxob3N0LmxvY2FsZG9tYWluggpsb2NhbGhvc3Q0ghdsb2NhbGhvc3Q0 16 | LmxvY2FsZG9tYWluNIIKbG9jYWxob3N0NoIXbG9jYWxob3N0Ni5sb2NhbGRvbWFp 17 | bjYwHQYDVR0OBBYEFFwNcqIKfGBCBGo9faQJ3TsHmp0SMA0GCSqGSIb3DQEBCwUA 18 | A4IBAQBvUJTRjSOf/+vtyS3OokwRilg1ZGF3psg0DWhjH2ehIRfNibU1Y8FVQo3I 19 | VU8LjcIUK1cN85z+AsYqLXo/C4qmJPydQ1tGpQL7uIrPD4h+Xh3tY6A2DKRJRQFO 20 | w2LjswPidGufMztpPbXxLREqvkvn80VkDnc44UPxYfHvZFqYwYyxZccA5mm+BhYu 21 | IerjfvgX+8zMWIQZOd+jRq8EaVTmVK2Azwwhc5ImWfc0DA3pmGPdECzE4N0VVoIJ 22 | N8PCVltXXP3F7K3LoT6CLSiJ3c/IDVNoVS4pRV6R6Y4oIKD9T/T1kAgAvOrUGRWY 23 | ejWQ41GdUmkmxrqCaMbVCO4s72BC 24 | -----END CERTIFICATE----- 25 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/transport/WithUriParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.transport; 21 | 22 | /** 23 | * Base interface for request builders that can load properties found in URI paths segments and query parameters. 24 | */ 25 | public interface WithUriParameter { 26 | 27 | /** 28 | * Set a URI path segment or query parameter property on this object. 29 | * 30 | * @param name the property name 31 | * @param value the property value 32 | * @return {@code true} if the property was found, {@code false} if the property is unknown 33 | * @throws RuntimeException if the value cannot be parsed to a valid property value 34 | */ 35 | boolean withUriParameter(String name, String value); 36 | } 37 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/_helpers/esql/jdbc/Cursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch._helpers.esql.jdbc; 21 | 22 | import java.sql.SQLException; 23 | import java.util.List; 24 | 25 | interface Cursor { 26 | 27 | List columns(); 28 | 29 | default int columnSize() { 30 | return columns().size(); 31 | } 32 | 33 | boolean next() throws SQLException; 34 | 35 | Object column(int column); 36 | 37 | /** 38 | * Number of rows that this cursor has pulled back from the 39 | * server in the current batch. 40 | */ 41 | int batchSize(); 42 | 43 | void close() throws SQLException; 44 | 45 | List warnings(); 46 | 47 | void clearWarnings(); 48 | } 49 | -------------------------------------------------------------------------------- /rest5-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/HttpGetWithEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package co.elastic.clients.transport.rest5_client.low_level; 20 | 21 | import org.apache.hc.client5.http.classic.methods.HttpGet; 22 | import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase; 23 | 24 | import java.net.URI; 25 | 26 | /** 27 | * Allows to send GET requests providing a body (not supported out of the box) 28 | */ 29 | final class HttpGetWithEntity extends HttpUriRequestBase { 30 | 31 | static final String METHOD_NAME = HttpGet.METHOD_NAME; 32 | 33 | HttpGetWithEntity(URI requestUri) { 34 | super(METHOD_NAME, requestUri); 35 | } 36 | 37 | @Override 38 | public String getMethod() { 39 | return METHOD_NAME; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /java-client/src/test/java/co/elastic/clients/elasticsearch/experiments/api/query2/QueryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch.experiments.api.query2; 21 | 22 | import org.junit.jupiter.api.Assertions; 23 | import org.junit.jupiter.api.Test; 24 | 25 | import java.util.Collection; 26 | 27 | public class QueryTest extends Assertions { 28 | @Test 29 | public void testQuery() { 30 | BoolQuery bq = new BoolQuery.Builder().build(); 31 | 32 | Query q = new Query(bq); 33 | 34 | assertEquals(Query.Kind.Bool, q._kind()); 35 | 36 | Query.Variant v = q._get(); 37 | assertEquals(Query.Kind.Bool, v._variantType()); 38 | 39 | Query q1 = v._toQuery(); 40 | 41 | Collection must = q.bool().must(); 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /rest5-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/HttpDeleteWithEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package co.elastic.clients.transport.rest5_client.low_level; 20 | 21 | import org.apache.hc.client5.http.classic.methods.HttpDelete; 22 | import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase; 23 | 24 | import java.net.URI; 25 | 26 | /** 27 | * Allows to send DELETE requests providing a body (not supported out of the box) 28 | */ 29 | final class HttpDeleteWithEntity extends HttpUriRequestBase { 30 | 31 | static final String METHOD_NAME = HttpDelete.METHOD_NAME; 32 | 33 | HttpDeleteWithEntity(URI requestUri) { 34 | super(METHOD_NAME, requestUri); 35 | } 36 | 37 | @Override 38 | public String getMethod() { 39 | return METHOD_NAME; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/util/TaggedUnion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.util; 21 | 22 | /** 23 | * Base interface for tagged union types (also known as sum types or variants). 24 | *

25 | * It provides access to the current variant kind and its value. 26 | * 27 | * @param the tag type that defines the possible variants (an enum). 28 | * @param the closest common ancestor type to all variant values. 29 | * 30 | * @see Tagged Union on Wikipedia 31 | */ 32 | public interface TaggedUnion, BaseType> { 33 | 34 | /** 35 | * Get the of the kind of variant held by this object. 36 | * 37 | * @return the variant kind 38 | */ 39 | Tag _kind(); 40 | 41 | BaseType _get(); 42 | } 43 | -------------------------------------------------------------------------------- /tools/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | plugins { 21 | java 22 | `java-test-fixtures` 23 | } 24 | 25 | tasks.withType { 26 | useJUnitPlatform() 27 | } 28 | 29 | java { 30 | targetCompatibility = JavaVersion.VERSION_17 31 | } 32 | 33 | dependencies { 34 | // EPL-2.0 35 | // https://junit.org/junit5/ 36 | testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.0") 37 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.0") 38 | } 39 | 40 | tasks.register("expand-includes") { 41 | workingDir = rootDir 42 | group = "application" 43 | mainClass.set("co.elastic.clients.tools.docs.IncludeExpander") 44 | args = listOf( 45 | "docs/reference", 46 | ) 47 | classpath = sourceSets["main"].runtimeClasspath 48 | } 49 | 50 | repositories { 51 | mavenCentral() 52 | } 53 | -------------------------------------------------------------------------------- /java-client/src/test/java/co/elastic/clients/transport/endpoints/BooleanEndpointTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.transport.endpoints; 21 | 22 | import co.elastic.clients.elasticsearch.core.ExistsRequest; 23 | import co.elastic.clients.elasticsearch.security.SamlCompleteLogoutRequest; 24 | import org.junit.jupiter.api.Assertions; 25 | import org.junit.jupiter.api.Test; 26 | 27 | public class BooleanEndpointTest extends Assertions { 28 | 29 | @Test 30 | public void testHasRequestBody() { 31 | ExistsRequest er = ExistsRequest.of(r -> r.index("foo").id("1")); 32 | assertNull(ExistsRequest._ENDPOINT.body(er)); 33 | 34 | SamlCompleteLogoutRequest sclr = SamlCompleteLogoutRequest.of(r -> r.ids("1").realm("r")); 35 | assertNotNull(SamlCompleteLogoutRequest._ENDPOINT.body(sclr)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/util/TriConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.util; 21 | 22 | /** 23 | * Represents an operation that accepts 3 input arguments and returns no 24 | * result. This is 3-arity specialization of {@link java.util.function.Consumer}. 25 | * Unlike most other functional interfaces, {@code TriConsumer} is expected 26 | * to operate via side-effects. 27 | * 28 | * @see java.util.function.Consumer 29 | * @see java.util.function.BiConsumer 30 | */ 31 | @FunctionalInterface 32 | public interface TriConsumer { 33 | 34 | /** 35 | * Performs this operation on the given arguments. 36 | * 37 | * @param t the first input argument 38 | * @param u the second input argument 39 | * @param v the third input argument 40 | */ 41 | void accept(T t, U u, V v); 42 | } 43 | -------------------------------------------------------------------------------- /docs/reference/transport/rest-client/sniffer/maven_repository.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/_maven_repository.html 4 | navigation_title: Maven Repository 5 | --- 6 | 7 | # Maven repository for {{es}} Java REST client sniffer [_maven_repository] 8 | 9 | :::{include} /reference/_snippets/legacy-rest-client.md 10 | ::: 11 | 12 | The REST client sniffer is subject to the same release cycle as Elasticsearch. Replace the version with the desired sniffer version, first released with `5.0.0-alpha4`. There is no relation between the sniffer version and the Elasticsearch version that the client can communicate with. Sniffer supports fetching the nodes list from Elasticsearch 2.x and onwards. 13 | 14 | If you are looking for a SNAPSHOT version, the Elastic Maven Snapshot repository is available at [https://snapshots.elastic.co/maven/](https://snapshots.elastic.co/maven/). 15 | 16 | ## Maven configuration [_maven_configuration] 17 | 18 | Here is how you can configure the dependency using maven as a dependency manager. Add the following to your `pom.xml` file: 19 | 20 | ```xml subs=true 21 | 22 | org.elasticsearch.client 23 | elasticsearch-rest-client-sniffer 24 | {{version}} 25 | 26 | ``` 27 | 28 | 29 | ## Gradle configuration [_gradle_configuration] 30 | 31 | Here is how you can configure the dependency using gradle as a dependency manager. Add the following to your `build.gradle` file: 32 | 33 | ```groovy subs=true 34 | dependencies { 35 | compile 'org.elasticsearch.client:elasticsearch-rest-client-sniffer:{{version}}' 36 | } 37 | ``` 38 | 39 | 40 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/document/comment/CommentForListDTO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.document.comment; 21 | 22 | import com.fasterxml.jackson.annotation.JsonFormat; 23 | import realworld.document.user.Author; 24 | 25 | import java.time.Instant; 26 | 27 | public record CommentForListDTO( 28 | Long id, 29 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", timezone = "UTC") 30 | Instant createdAt, 31 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", timezone = "UTC") 32 | Instant updatedAt, 33 | String body, 34 | Author author) { 35 | 36 | public CommentForListDTO(Comment comment) { 37 | this(comment.id(), comment.createdAt(), 38 | comment.updatedAt(), comment.body(), 39 | comment.author()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /java-client/src/test/java/co/elastic/clients/elasticsearch/experiments/api/DateMathTimeUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch.experiments.api; 21 | 22 | import co.elastic.clients.json.JsonEnum; 23 | import co.elastic.clients.json.JsonpDeserializer; 24 | 25 | public enum DateMathTimeUnit implements JsonEnum { 26 | 27 | Year("Y"), 28 | Month("M"), 29 | Day("D"), 30 | Hour("h"), 31 | Minute("m"), 32 | Second("s"); 33 | 34 | private final String jsonValue; 35 | 36 | DateMathTimeUnit(String jsonValue) { 37 | this.jsonValue = jsonValue; 38 | } 39 | 40 | public String jsonValue() { 41 | return this.jsonValue; 42 | } 43 | 44 | public static final JsonpDeserializer PARSER; 45 | 46 | static { 47 | PARSER = new Deserializer<>(DateMathTimeUnit.values()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /java-client/src/test/java/co/elastic/clients/util/DuplicateResourceFinderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.util; 21 | 22 | import com.fasterxml.jackson.databind.ext.CoreXMLSerializers; 23 | import org.junit.jupiter.api.Assertions; 24 | import org.junit.jupiter.api.Test; 25 | 26 | class DuplicateResourceFinderTest extends Assertions { 27 | 28 | @Test 29 | public void testDuplicateCheck() { 30 | 31 | Exception e = assertThrows(RuntimeException.class, () -> { 32 | DuplicateResourceFinder.ensureClassUniqueness(CoreXMLSerializers.class); 33 | }); 34 | assertTrue(e.getMessage().contains("Several versions of")); 35 | 36 | // Disabling the test should not throw an exception 37 | DuplicateResourceFinder.enableCheck(false); 38 | DuplicateResourceFinder.ensureClassUniqueness(CoreXMLSerializers.class); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/json/JsonpDeserializable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json; 21 | 22 | import java.lang.annotation.Documented; 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.RetentionPolicy; 26 | import java.lang.annotation.Target; 27 | 28 | /** 29 | * Indicates that a class has a {@link JsonpDeserializer} as a static field. 30 | */ 31 | @Target({ElementType.TYPE}) 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Documented 34 | public @interface JsonpDeserializable { 35 | /** 36 | * The name of the public static field of the class of type {@link JsonpDeserializer} that can be used to 37 | * deserialize JSON to an instance of this class. 38 | * 39 | * @return the deserializer field name 40 | */ 41 | String field() default "_DESERIALIZER"; 42 | } 43 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/util/QuadConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.util; 21 | 22 | /** 23 | * Represents an operation that accepts 4 input arguments and returns no 24 | * result. This is 4-arity specialization of {@link java.util.function.Consumer}. 25 | * Unlike most other functional interfaces, {@code QuadConsumer} is expected 26 | * to operate via side-effects. 27 | * 28 | * @see java.util.function.Consumer 29 | * @see java.util.function.BiConsumer 30 | */ 31 | @FunctionalInterface 32 | public interface QuadConsumer { 33 | 34 | /** 35 | * Performs this operation on the given arguments. 36 | * 37 | * @param t the first input argument 38 | * @param u the second input argument 39 | * @param v the third input argument 40 | * @param x the fourth input argument 41 | */ 42 | void accept(T t, U u, V v, X x); 43 | } 44 | -------------------------------------------------------------------------------- /example-transports/src/test/java/co/elastic/clients/transport/rest_client/RestTransportClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.transport.rest_client; 21 | 22 | import co.elastic.clients.transport.TransportHttpClientTest; 23 | import co.elastic.clients.transport.rest5_client.Rest5ClientHttpClient; 24 | import org.apache.http.HttpHost; 25 | import org.elasticsearch.client.RestClient; 26 | 27 | public class RestTransportClientTest extends TransportHttpClientTest { 28 | 29 | public RestTransportClientTest() { 30 | super(createClient()); 31 | } 32 | 33 | private static Rest5ClientHttpClient createClient() { 34 | RestClient restClient = RestClient.builder( 35 | new HttpHost(server.getAddress().getAddress(), server.getAddress().getPort(), "http") 36 | ).build(); 37 | 38 | return new Rest5ClientHttpClient(restClient); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /java-client/src/test/java/co/elastic/clients/json/JsonpDeserializerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json; 21 | 22 | import co.elastic.clients.testkit.ModelTestCase; 23 | import jakarta.json.stream.JsonParser; 24 | import org.junit.jupiter.api.Test; 25 | 26 | import java.io.StringReader; 27 | import java.util.List; 28 | 29 | public class JsonpDeserializerTest extends ModelTestCase { 30 | 31 | @Test 32 | public void testNullStringInArray() { 33 | JsonpDeserializer> deser = JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()); 34 | 35 | JsonParser parser = mapper.jsonProvider().createParser(new StringReader("[\"a\", null, \"b\"]")); 36 | List list = deser.deserialize(parser, mapper); 37 | 38 | assertEquals("a", list.get(0)); 39 | assertNull(list.get(1)); 40 | assertEquals("b", list.get(2)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/json/ToStringMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json; 21 | 22 | import jakarta.json.stream.JsonGenerator; 23 | 24 | class ToStringMapper extends SimpleJsonpMapper { 25 | 26 | static final ToStringMapper INSTANCE = new ToStringMapper(); 27 | 28 | private static final JsonpSerializer toStringSerializer = new JsonpSerializer() { 29 | @Override 30 | public void serialize(Object value, JsonGenerator generator, JsonpMapper mapper) { 31 | if (value == null) { 32 | generator.writeNull(); 33 | } else { 34 | generator.write(value.toString()); 35 | } 36 | } 37 | }; 38 | 39 | @Override 40 | @SuppressWarnings("unchecked") 41 | protected JsonpSerializer getDefaultSerializer(T value) { 42 | return (JsonpSerializer)toStringSerializer; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /java-client/src/test/java/co/elastic/clients/documentation/usage/Product.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.documentation.usage; 21 | 22 | public class Product { 23 | private String sku; 24 | private String name; 25 | private double price; 26 | 27 | public Product() {} 28 | public Product(String sku, String name, double price) { 29 | this.sku = sku; 30 | this.name = name; 31 | this.price = price; 32 | } 33 | 34 | public String getSku() { 35 | return sku; 36 | } 37 | 38 | public void setSku(String sku) { 39 | this.sku = sku; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public double getPrice() { 51 | return this.price; 52 | } 53 | 54 | public void setPrice(double price) { 55 | this.price = price; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /example-transports/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | plugins { 21 | java 22 | `java-library` 23 | `java-test-fixtures` 24 | } 25 | 26 | tasks.withType { 27 | useJUnitPlatform() 28 | } 29 | 30 | java { 31 | targetCompatibility = JavaVersion.VERSION_17 32 | } 33 | 34 | 35 | dependencies { 36 | val jacksonVersion = "2.17.0" 37 | 38 | api("io.netty", "netty-codec-http", "4.1.93.Final") 39 | 40 | implementation(project(":java-client")) 41 | 42 | // Apache 2.0 43 | // https://github.com/FasterXML/jackson 44 | testImplementation("com.fasterxml.jackson.core", "jackson-core", jacksonVersion) 45 | testImplementation("com.fasterxml.jackson.core", "jackson-databind", jacksonVersion) 46 | 47 | // EPL-2.0 48 | // https://junit.org/junit5/ 49 | testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.0") 50 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.0") 51 | 52 | } 53 | repositories { 54 | mavenCentral() 55 | } 56 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | The Elasticsearch Java client is open source and we love to receive contributions from our community. 4 | 5 | There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests or writing code. 6 | 7 | ## Sign the Contributor License Agreement 8 | 9 | We do ask that you sign the [Contiributor License Agreement](https://www.elastic.co/contributor-agreement) 10 | before we can accept pull requests from you. 11 | 12 | ## Development 13 | 14 | ### Prerequisites 15 | 16 | You need at least Java 17 to build the project. The project is built with `Gradle`. You don't have to install it, and can use the provided `gradlew` that will install the required version if needed. 17 | 18 | Docker is used for some tests to spawn an Elasticsearch server. 19 | 20 | ### Project structure 21 | 22 | This is a multi-project build. The Java client is in the [`java-client`](./java-client) subproject. Additional subprojects will come with more extensive API tests and examples. 23 | 24 | The `co.elastic.clients.elasticsearch` package and its children are all entirely generated, and the generator is not part of this repository. Because of this, PRs will not work for this part of the code. If you want to suggest changes to the generated code, open an issue describing how the code should look like, so that we can discuss on updating the generator. 25 | 26 | Other packages contain support classes and frameworks that provide the plumbing between the generated code and the http client and JSON object mapping libraries. PRs are more than welcome on code in these packages. 27 | 28 | ### Before you open a PR 29 | 30 | To save everybody's time, please make sure that `./gradlew check` is successful before opening a PR with your changes. This will check the code style and run the tests. 31 | -------------------------------------------------------------------------------- /java-client/src/test/java/co/elastic/clients/util/PairTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.util; 21 | 22 | import co.elastic.clients.elasticsearch._types.FieldValue; 23 | import co.elastic.clients.testkit.ModelTestCase; 24 | import co.elastic.clients.elasticsearch.watcher.Condition; 25 | import co.elastic.clients.elasticsearch.watcher.ConditionOp; 26 | import org.junit.jupiter.api.Test; 27 | 28 | class PairTest extends ModelTestCase { 29 | 30 | @Test 31 | public void testCondition() { 32 | 33 | String json = "{\"compare\":{\"foo\":{\"eq\":\"bar\"}}}"; 34 | 35 | Condition c = Condition.of(b -> b 36 | .compare(NamedValue.of("foo", Pair.of(ConditionOp.Eq, FieldValue.of("bar")))) 37 | ); 38 | 39 | c = checkJsonRoundtrip(c, json); 40 | 41 | assertEquals("foo", c.compare().name()); 42 | assertEquals(ConditionOp.Eq, c.compare().value().key()); 43 | assertEquals("bar", c.compare().value().value().stringValue()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/_types/query_dsl/PinnedQueryVariant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch._types.query_dsl; 21 | 22 | //---------------------------------------------------------------- 23 | // THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. 24 | //---------------------------------------------------------------- 25 | // 26 | // This code is generated from the Elasticsearch API specification 27 | // at https://github.com/elastic/elasticsearch-specification 28 | // 29 | // Manual updates to this file will be lost when the code is 30 | // re-generated. 31 | // 32 | // If you find a property that is missing or wrongly typed, please 33 | // open an issue or a PR on the API specification repository. 34 | // 35 | //---------------------------------------------------------------- 36 | 37 | /** 38 | * Base interface for {@link PinnedQuery} variants. 39 | */ 40 | public interface PinnedQueryVariant { 41 | 42 | PinnedQuery.Kind _pinnedQueryKind(); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/json/UnexpectedJsonEventException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json; 21 | 22 | import jakarta.json.stream.JsonParser; 23 | import jakarta.json.stream.JsonParser.Event; 24 | import jakarta.json.stream.JsonParsingException; 25 | 26 | import java.util.EnumSet; 27 | 28 | public class UnexpectedJsonEventException extends JsonParsingException { 29 | public UnexpectedJsonEventException(JsonParser parser, Event event) { 30 | super("Unexpected JSON event '" + event + "'", parser.getLocation()); 31 | } 32 | 33 | public UnexpectedJsonEventException(JsonParser parser, Event event, Event expected) { 34 | super("Unexpected JSON event '" + event + "' instead of '" + expected + "'", parser.getLocation()); 35 | } 36 | 37 | public UnexpectedJsonEventException(JsonParser parser, Event event, EnumSet expected) { 38 | super("Unexpected JSON event '" + event + "' instead of '" + expected + "'", parser.getLocation()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/_types/query_dsl/GeoGridQueryVariant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch._types.query_dsl; 21 | 22 | //---------------------------------------------------------------- 23 | // THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. 24 | //---------------------------------------------------------------- 25 | // 26 | // This code is generated from the Elasticsearch API specification 27 | // at https://github.com/elastic/elasticsearch-specification 28 | // 29 | // Manual updates to this file will be lost when the code is 30 | // re-generated. 31 | // 32 | // If you find a property that is missing or wrongly typed, please 33 | // open an issue or a PR on the API specification repository. 34 | // 35 | //---------------------------------------------------------------- 36 | 37 | /** 38 | * Base interface for {@link GeoGridQuery} variants. 39 | */ 40 | public interface GeoGridQueryVariant { 41 | 42 | GeoGridQuery.Kind _geoGridQueryKind(); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/json/JsonLocationImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json; 21 | 22 | import jakarta.json.stream.JsonLocation; 23 | 24 | class JsonLocationImpl implements JsonLocation { 25 | 26 | private final long columnNo; 27 | private final long lineNo; 28 | private final long offset; 29 | 30 | JsonLocationImpl(long lineNo, long columnNo, long streamOffset) { 31 | this.lineNo = lineNo; 32 | this.columnNo = columnNo; 33 | this.offset = streamOffset; 34 | } 35 | 36 | @Override 37 | public long getLineNumber() { 38 | return lineNo; 39 | } 40 | 41 | @Override 42 | public long getColumnNumber() { 43 | return columnNo; 44 | } 45 | 46 | @Override 47 | public long getStreamOffset() { 48 | return offset; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return "(line no=" + lineNo + ", column no=" + columnNo + ", offset=" + offset + ")"; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/_types/query_dsl/IntervalsQueryVariant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch._types.query_dsl; 21 | 22 | //---------------------------------------------------------------- 23 | // THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. 24 | //---------------------------------------------------------------- 25 | // 26 | // This code is generated from the Elasticsearch API specification 27 | // at https://github.com/elastic/elasticsearch-specification 28 | // 29 | // Manual updates to this file will be lost when the code is 30 | // re-generated. 31 | // 32 | // If you find a property that is missing or wrongly typed, please 33 | // open an issue or a PR on the API specification repository. 34 | // 35 | //---------------------------------------------------------------- 36 | 37 | /** 38 | * Base interface for {@link IntervalsQuery} variants. 39 | */ 40 | public interface IntervalsQueryVariant { 41 | 42 | IntervalsQuery.Kind _intervalsQueryKind(); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/util/TriFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.util; 21 | 22 | /** 23 | * Represents a function that accepts 3 arguments and produces a result. 24 | * This is the 3-arity specialization of {@link java.util.function.Function}. 25 | * 26 | * @param the type of the first argument to the function 27 | * @param the type of the second argument to the function 28 | * @param the type of the third argument to the function 29 | * @param the type of the result of the function 30 | * 31 | * @see java.util.function.Function 32 | * @see java.util.function.BiFunction 33 | */ 34 | @FunctionalInterface 35 | public interface TriFunction { 36 | 37 | /** 38 | * Applies this function to the given arguments. 39 | * 40 | * @param t the first function argument 41 | * @param u the second function argument 42 | * @param v the third function argument 43 | * @return the function result 44 | */ 45 | R apply(T t, U u, V v); 46 | } 47 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/_types/RankVariant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch._types; 21 | 22 | //---------------------------------------------------------------- 23 | // THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. 24 | //---------------------------------------------------------------- 25 | // 26 | // This code is generated from the Elasticsearch API specification 27 | // at https://github.com/elastic/elasticsearch-specification 28 | // 29 | // Manual updates to this file will be lost when the code is 30 | // re-generated. 31 | // 32 | // If you find a property that is missing or wrongly typed, please 33 | // open an issue or a PR on the API specification repository. 34 | // 35 | //---------------------------------------------------------------- 36 | 37 | /** 38 | * Base interface for {@link Rank} variants. 39 | */ 40 | public interface RankVariant { 41 | 42 | Rank.Kind _rankKind(); 43 | 44 | default Rank _toRank() { 45 | return new Rank(this); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/json/jackson/JacksonUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.json.jackson; 21 | 22 | import com.fasterxml.jackson.core.JsonParseException; 23 | import jakarta.json.JsonException; 24 | import jakarta.json.stream.JsonGenerationException; 25 | import jakarta.json.stream.JsonParsingException; 26 | 27 | import java.io.IOException; 28 | 29 | class JacksonUtils { 30 | public static JsonException convertException(IOException ioe) { 31 | if (ioe instanceof com.fasterxml.jackson.core.JsonGenerationException) { 32 | return new JsonGenerationException(ioe.getMessage(), ioe); 33 | 34 | } else if (ioe instanceof com.fasterxml.jackson.core.JsonParseException) { 35 | JsonParseException jpe = (JsonParseException) ioe; 36 | return new JsonParsingException(ioe.getMessage(), jpe, new JacksonJsonpLocation(jpe.getLocation())); 37 | 38 | } else { 39 | return new JsonException("Jackson exception", ioe); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/transform/SyncVariant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch.transform; 21 | 22 | //---------------------------------------------------------------- 23 | // THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. 24 | //---------------------------------------------------------------- 25 | // 26 | // This code is generated from the Elasticsearch API specification 27 | // at https://github.com/elastic/elasticsearch-specification 28 | // 29 | // Manual updates to this file will be lost when the code is 30 | // re-generated. 31 | // 32 | // If you find a property that is missing or wrongly typed, please 33 | // open an issue or a PR on the API specification repository. 34 | // 35 | //---------------------------------------------------------------- 36 | 37 | /** 38 | * Base interface for {@link Sync} variants. 39 | */ 40 | public interface SyncVariant { 41 | 42 | Sync.Kind _syncKind(); 43 | 44 | default Sync _toSync() { 45 | return new Sync(this); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/util/VisibleForTesting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.util; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | /** 28 | * Annotates a program element that exists, or is more widely visible than otherwise necessary, only 29 | * for use in test code. 30 | * 31 | *

Do not use this interface for public or protected declarations: it is a fig leaf for 32 | * bad design, and it does not prevent anyone from using the declaration---and experience has shown 33 | * that they will. 34 | * 35 | *

Borrowed from 36 | * Guava. 37 | */ 38 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.TYPE}) 39 | @Retention(RetentionPolicy.SOURCE) 40 | public @interface VisibleForTesting { 41 | } 42 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/_types/query_dsl/SparseVectorQueryVariant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch._types.query_dsl; 21 | 22 | //---------------------------------------------------------------- 23 | // THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. 24 | //---------------------------------------------------------------- 25 | // 26 | // This code is generated from the Elasticsearch API specification 27 | // at https://github.com/elastic/elasticsearch-specification 28 | // 29 | // Manual updates to this file will be lost when the code is 30 | // re-generated. 31 | // 32 | // If you find a property that is missing or wrongly typed, please 33 | // open an issue or a PR on the API specification repository. 34 | // 35 | //---------------------------------------------------------------- 36 | 37 | /** 38 | * Base interface for {@link SparseVectorQuery} variants. 39 | */ 40 | public interface SparseVectorQueryVariant { 41 | 42 | SparseVectorQuery.Kind _sparseVectorQueryKind(); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/ingest/DatabaseConfigurationVariant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch.ingest; 21 | 22 | //---------------------------------------------------------------- 23 | // THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. 24 | //---------------------------------------------------------------- 25 | // 26 | // This code is generated from the Elasticsearch API specification 27 | // at https://github.com/elastic/elasticsearch-specification 28 | // 29 | // Manual updates to this file will be lost when the code is 30 | // re-generated. 31 | // 32 | // If you find a property that is missing or wrongly typed, please 33 | // open an issue or a PR on the API specification repository. 34 | // 35 | //---------------------------------------------------------------- 36 | 37 | /** 38 | * Base interface for {@link DatabaseConfiguration} variants. 39 | */ 40 | public interface DatabaseConfigurationVariant { 41 | 42 | DatabaseConfiguration.Kind _databaseConfigurationKind(); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/watcher/InputVariant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch.watcher; 21 | 22 | //---------------------------------------------------------------- 23 | // THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. 24 | //---------------------------------------------------------------- 25 | // 26 | // This code is generated from the Elasticsearch API specification 27 | // at https://github.com/elastic/elasticsearch-specification 28 | // 29 | // Manual updates to this file will be lost when the code is 30 | // re-generated. 31 | // 32 | // If you find a property that is missing or wrongly typed, please 33 | // open an issue or a PR on the API specification repository. 34 | // 35 | //---------------------------------------------------------------- 36 | 37 | /** 38 | * Base interface for {@link Input} variants. 39 | */ 40 | public interface InputVariant { 41 | 42 | Input.Kind _inputKind(); 43 | 44 | default Input _toInput() { 45 | return new Input(this); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /docs/reference/transport/rest-client/usage/maven.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/java-rest-low-usage-maven.html 4 | navigation_title: Maven repository 5 | --- 6 | 7 | # Maven repository for {{es}} Java REST client [java-rest-low-usage-maven] 8 | 9 | :::{include} /reference/_snippets/legacy-rest-client.md 10 | ::: 11 | 12 | The low-level Java REST client is hosted on [Maven Central](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.elasticsearch.client%22). The minimum Java version required is `1.8`. 13 | 14 | The low-level REST client is subject to the same release cycle as Elasticsearch. Replace the version with the desired client version, first released with `5.0.0-alpha4`. There is no relation between the client version and the Elasticsearch version that the client can communicate with. The low-level REST client is compatible with all Elasticsearch versions. 15 | 16 | If you are looking for a SNAPSHOT version, the Elastic Maven Snapshot repository is available at [https://snapshots.elastic.co/maven/](https://snapshots.elastic.co/maven/). 17 | 18 | ## Maven configuration [java-rest-low-usage-maven-maven] 19 | 20 | Here is how you can configure the dependency using maven as a dependency manager. Add the following to your `pom.xml` file: 21 | 22 | ```xml subs=true 23 | 24 | org.elasticsearch.client 25 | elasticsearch-rest-client 26 | {{version}} 27 | 28 | ``` 29 | 30 | 31 | ## Gradle configuration [java-rest-low-usage-maven-gradle] 32 | 33 | Here is how you can configure the dependency using gradle as a dependency manager. Add the following to your `build.gradle` file: 34 | 35 | ```groovy subs=true 36 | dependencies { 37 | compile 'org.elasticsearch.client:elasticsearch-rest-client:{{version}}' 38 | } 39 | ``` 40 | 41 | 42 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/_types/query_dsl/QueryVariant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch._types.query_dsl; 21 | 22 | //---------------------------------------------------------------- 23 | // THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. 24 | //---------------------------------------------------------------- 25 | // 26 | // This code is generated from the Elasticsearch API specification 27 | // at https://github.com/elastic/elasticsearch-specification 28 | // 29 | // Manual updates to this file will be lost when the code is 30 | // re-generated. 31 | // 32 | // If you find a property that is missing or wrongly typed, please 33 | // open an issue or a PR on the API specification repository. 34 | // 35 | //---------------------------------------------------------------- 36 | 37 | /** 38 | * Base interface for {@link Query} variants. 39 | */ 40 | public interface QueryVariant { 41 | 42 | Query.Kind _queryKind(); 43 | 44 | default Query _toQuery() { 45 | return new Query(this); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/watcher/TriggerVariant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch.watcher; 21 | 22 | //---------------------------------------------------------------- 23 | // THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. 24 | //---------------------------------------------------------------- 25 | // 26 | // This code is generated from the Elasticsearch API specification 27 | // at https://github.com/elastic/elasticsearch-specification 28 | // 29 | // Manual updates to this file will be lost when the code is 30 | // re-generated. 31 | // 32 | // If you find a property that is missing or wrongly typed, please 33 | // open an issue or a PR on the API specification repository. 34 | // 35 | //---------------------------------------------------------------- 36 | 37 | /** 38 | * Base interface for {@link Trigger} variants. 39 | */ 40 | public interface TriggerVariant { 41 | 42 | Trigger.Kind _triggerKind(); 43 | 44 | default Trigger _toTrigger() { 45 | return new Trigger(this); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /examples/realworld-app/rw-database/src/main/java/realworld/utils/Utility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package realworld.utils; 21 | 22 | import co.elastic.clients.elasticsearch.core.SearchResponse; 23 | 24 | import java.util.Objects; 25 | 26 | public class Utility { 27 | 28 | public static boolean isNullOrBlank(String s) { 29 | return Objects.isNull(s) || s.isBlank(); 30 | } 31 | 32 | /** 33 | * Utility method to be used for single result queries. 34 | * 35 | * @return The document id. 36 | */ 37 | public static String extractId(SearchResponse searchResponse) { 38 | return searchResponse.hits().hits().getFirst().id(); 39 | } 40 | 41 | /** 42 | * Utility method to be used for single result queries. 43 | * 44 | * @return An object of the class that was specified in the query definition. 45 | */ 46 | public static TDocument extractSource(SearchResponse searchResponse) { 47 | return searchResponse.hits().hits().getFirst().source(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/ingest/DatabaseConfigurationFullVariant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch.ingest; 21 | 22 | //---------------------------------------------------------------- 23 | // THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. 24 | //---------------------------------------------------------------- 25 | // 26 | // This code is generated from the Elasticsearch API specification 27 | // at https://github.com/elastic/elasticsearch-specification 28 | // 29 | // Manual updates to this file will be lost when the code is 30 | // re-generated. 31 | // 32 | // If you find a property that is missing or wrongly typed, please 33 | // open an issue or a PR on the API specification repository. 34 | // 35 | //---------------------------------------------------------------- 36 | 37 | /** 38 | * Base interface for {@link DatabaseConfigurationFull} variants. 39 | */ 40 | public interface DatabaseConfigurationFullVariant { 41 | 42 | DatabaseConfigurationFull.Kind _databaseConfigurationFullKind(); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /java-client/src/main/java/co/elastic/clients/elasticsearch/_helpers/esql/EsqlAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to Elasticsearch B.V. under one or more contributor 3 | * license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright 5 | * ownership. Elasticsearch B.V. licenses this file to you under 6 | * the Apache License, Version 2.0 (the "License"); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package co.elastic.clients.elasticsearch._helpers.esql; 21 | 22 | import co.elastic.clients.ApiClient; 23 | import co.elastic.clients.elasticsearch.esql.QueryRequest; 24 | import co.elastic.clients.transport.ElasticsearchTransport; 25 | import co.elastic.clients.transport.endpoints.BinaryResponse; 26 | 27 | import java.io.IOException; 28 | 29 | /** 30 | * A deserializer for ES|QL responses. 31 | */ 32 | public interface EsqlAdapter { 33 | /** 34 | * ESQL result format this deserializer accepts (text, csv, json, arrow, etc.) 35 | */ 36 | String format(); 37 | 38 | /** 39 | * For JSON like results, whether the result should be organized in rows or columns 40 | */ 41 | boolean columnar(); 42 | 43 | /** 44 | * Deserialize the raw http response returned by the server 45 | */ 46 | Result deserialize(ApiClient client, QueryRequest request, BinaryResponse response) throws IOException; 47 | } 48 | --------------------------------------------------------------------------------