Skip to content

Commit e8423e1

Browse files
swallezszabosteve
andauthored
[docs] Update with the latest changes and use compilable examples (#52)
Co-authored-by: István Zoltán Szabó <istvan.szabo@elastic.co>
1 parent f5070c7 commit e8423e1

File tree

10 files changed

+208
-187
lines changed

10 files changed

+208
-187
lines changed

docs/api-conventions.asciidoc

Lines changed: 135 additions & 114 deletions
Large diffs are not rendered by default.

docs/connecting.asciidoc

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
[[connecting]]
22
== Connecting
33

4-
beta[]
5-
6-
The Java client is structured around three main components:
4+
The {java-client} is structured around three main components:
75

86
* **API client classes**. These provide strongly typed data structures and
97
methods for {es} APIs. Since the {es} API is large, it is structured in feature
@@ -18,16 +16,7 @@ This code snippet creates and wires together these three components:
1816

1917
["source","java"]
2018
--------------------------------------------------
21-
// Create the low-level client
22-
RestClient restClient = RestClient.builder(
23-
new HttpHost("localhost", 9200)).build();
24-
25-
// Create the transport with a Jackson mapper
26-
Transport transport = new RestClientTransport(
27-
restClient, new JacksonJsonpMapper());
28-
29-
// And create the API client
30-
ElasticsearchClient client = new ElasticsearchClient(transport);
19+
include-tagged::{doc-tests}/ConnectingTest.java[create-client]
3120
--------------------------------------------------
3221

3322
Authentication is managed by the <<java-rest-low>>. For further details on
@@ -46,16 +35,5 @@ concise DSL-like code. This pattern is explained in more detail in
4635

4736
["source","java"]
4837
--------------------------------------------------
49-
SearchResponse<Product> search = client.search(s -> s
50-
.index("products")
51-
.query(q -> q
52-
.term(t -> t
53-
.field("name")
54-
.value("bicycle")
55-
)),
56-
Product.class);
57-
58-
for (Hit<AppData> hit: search.hits().hits()) {
59-
processAppData(hit.source());
60-
}
61-
--------------------------------------------------
38+
include-tagged::{doc-tests}/ConnectingTest.java[first-request]
39+
--------------------------------------------------

docs/index-local.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Allow building docs locally without a checkout of the Elasticsearch repo
2+
:elasticsearch-root: {docdir}/local/elasticsearch
3+
4+
include::index.asciidoc[]

docs/index.asciidoc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@
33
:branch: master
44
include::{asciidoc-dir}/../../shared/attributes.asciidoc[]
55

6+
:version: 7.16.0
7+
:java-client: Java API Client
8+
:doc-tests: {docdir}/../java-client/src/test/java/co/elastic/clients/documentation
9+
610
include::introduction.asciidoc[]
711
include::installation.asciidoc[]
812
include::connecting.asciidoc[]
913
include::migrate.asciidoc[]
1014
include::api-conventions.asciidoc[]
11-
include::{elasticsearch-root}/docs/java-rest/low-level/index.asciidoc[]
15+
16+
:version!:
17+
:java-client!:
18+
:doc-tests!:
19+
20+
include::{elasticsearch-root}/docs/java-rest/low-level/index.asciidoc[]

docs/installation.asciidoc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
[[installation]]
22
== Installation
33

4-
beta[]
5-
64
Requirements:
75

86
* Java 8 or later.
9-
* Optionally, a JSON object mapping library to allow seamless integration of
7+
* A JSON object mapping library to allow seamless integration of
108
your application classes with the Elasticsearch API. The Java client has
119
support for https://github.com/FasterXML/jackson[Jackson] or a
1210
http://json-b.net/[JSON-B] library like
@@ -23,10 +21,10 @@ available at https://snapshots.elastic.co/maven/.
2321
[[gradle]]
2422
=== Installation in a Gradle project by using Jackson
2523

26-
["source","groovy",subs="attributes"]
24+
["source","groovy",subs="attributes+"]
2725
--------------------------------------------------
2826
dependencies {
29-
implementation 'co.elastic.clients:elasticsearch-java:7.15.0'
27+
implementation 'co.elastic.clients:elasticsearch-java:{version}'
3028
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
3129
}
3230
--------------------------------------------------
@@ -38,15 +36,15 @@ dependencies {
3836
In the `pom.xml` of your project, add the following repository definition and
3937
dependencies:
4038

41-
["source","xml",subs="attributes"]
39+
["source","xml",subs="attributes+"]
4240
--------------------------------------------------
4341
<project>
4442
4543
<dependencies>
4644
<dependency>
4745
<groupId>co.elastic.clients</groupId>
4846
<artifactId>elasticsearch-java</artifactId>
49-
<version>7.15.0</version>
47+
<version>{version}</version>
5048
</dependency>
5149
<dependency>
5250
<groupId>com.fasterxml.jackson.core</groupId>
@@ -56,4 +54,4 @@ dependencies:
5654
</dependencies>
5755
5856
</project>
59-
--------------------------------------------------
57+
--------------------------------------------------

docs/introduction.asciidoc

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
[[introduction]]
22
== Introduction
33

4-
beta[]
5-
64
This is the documentation for the official Java API Client for {es}. The client
75
provides strongly typed requests and responses for all {es} APIs.
86

@@ -20,29 +18,32 @@ provides strongly typed requests and responses for all {es} APIs.
2018
retries, node discovery, and so on.
2119

2220
[discrete]
23-
=== Beta status
24-
25-
The Java API Client is a new product and is still in beta. What this means in
26-
concrete terms:
27-
28-
* Although the general structure will not change, some renaming may happen to
29-
improve ease of use.
30-
* Some APIs may not be implemented yet. The code for APIs is generated from the
31-
https://github.com/elastic/elasticsearch-specification[{es} API specification]
32-
where complete coverage is targeted for the GA release of the Java client.
33-
* Some complex API data types are not yet fully supported. This revolves mostly
34-
around union types where the JSON API accepts many different shapes for some
35-
property. These types are currently represented as raw `JsonValue` objects.
36-
* Some built-in types like dates are represented as primitive strings.
37-
Additional support for standard JDK types will be added for the GA release.
21+
=== Main changes since version 7.15
22+
23+
Version 7.15 of the {java-client} was a beta release. We learned a lot from the
24+
initial feedback and this led to a few breaking changes in this version:
25+
26+
* the `_core` package that contains top-level {es} APIs has been renamed to `core`.
27+
* property setters for lists and maps have been revisited.
28+
* all API data types are now supported, and there are no more raw `JsonValue` properties.
29+
* the supporting JSON framework and transport classes have been refactored and improved.
30+
However the high level APIs used by applications haven't changed so there should be
31+
no of very little impact on existing application code.
32+
33+
This version of the {java-client} supports all {es} APIs are implemented except the
34+
Vector tile search API and the Find structure API.
35+
36+
While this version is considered stable, most of the code is generated from the
37+
https://github.com/elastic/elasticsearch-specification[{es} API specification] where
38+
some of the less often used {es} APIs still need to be fully validated. Changes in
39+
the specification that may impact application code will be clearly identified in later
40+
versions of the Java API client.
3841

3942
[discrete]
4043
=== Compatibility
4144

42-
The main branch targets the next major release (8.0), the 7.x branch targets the
43-
next minor release for the 7.x series. Support is still incomplete as the API
44-
code is generated from the {es} Specification that is also still a work in
45-
progress.
45+
The `main` branch targets the next major release (8.0), the `7.x` branch targets the
46+
next minor release for the `7.x` series.
4647

4748
The {es} Java client is forward compatible; meaning that the client supports
4849
communicating with greater or equal minor versions of {es}. {es} language

docs/local/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This directory contains stubs that allow building the Java client docs in isolation following the instructions in "[Building documentation for a local repo](https://github.com/elastic/docs#building-documentation)".
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[[java-rest-low]]
2+
== Java Low Level REST Client
3+
4+
This is a stub for the Java Low Level REST Client.

docs/migrate.asciidoc

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,5 @@ The code below shows how to initialize both clients with the same HTTP client:
3939

4040
["source","java"]
4141
--------------------------------------------------
42-
// Create the low-level client
43-
RestClientBuilder httpClientBuilder = RestClient.builder(
44-
new HttpHost("localhost", 9200)
45-
);
46-
47-
// Create the HLRC
48-
RestHighLevelClient hlrc = new RestHighLevelClient(httpClientBuilder);
49-
50-
// Create the new Java Client with the same low level client
51-
Transport transport = new RestClientTransport(
52-
hlrc.getLowLevelClient(),
53-
new JacksonJsonpMapper()
54-
);
55-
56-
ElasticsearchClient esClient = new ElasticsearchClient(transport);
57-
58-
// hlrc and esClient share the same httpClient
42+
include-tagged::{doc-tests}/MigrateHlrcTest.java[migrate]
5943
--------------------------------------------------

java-client/src/test/java/co/elastic/clients/documentation/ApiConventionsTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
2323
import co.elastic.clients.elasticsearch.ElasticsearchClient;
24+
import co.elastic.clients.elasticsearch._types.NodeStatistics;
2425
import co.elastic.clients.elasticsearch._types.SortOrder;
2526
import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
2627
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
@@ -31,6 +32,7 @@
3132
import co.elastic.clients.elasticsearch.indices.CreateIndexResponse;
3233
import co.elastic.clients.transport.ElasticsearchTransport;
3334
import co.elastic.clients.transport.TransportException;
35+
import co.elastic.clients.util.ApiTypeHelper;
3436
import org.junit.Assert;
3537
import org.junit.Test;
3638

@@ -234,6 +236,25 @@ public void collections() {
234236

235237
}
236238

239+
@Test
240+
public void optionalCollections() {
241+
//tag::optional-collections
242+
NodeStatistics stats = NodeStatistics.of(b -> b
243+
.total(1)
244+
.failed(0)
245+
.successful(1)
246+
);
247+
248+
// The `failures` list was not provided.
249+
// - it's not null
250+
assertNotNull(stats.failures());
251+
// - it's empty
252+
assertEquals(0, stats.failures().size());
253+
// - and if needed we can know it was actually not defined
254+
assertFalse(ApiTypeHelper.isDefined(stats.failures()));
255+
//end::optional-collections
256+
}
257+
237258
private void doSomething(Object... o) {
238259

239260
}

0 commit comments

Comments
 (0)