Skip to content

Commit 266c902

Browse files
committed
Use a more mystmd-y syntax
1 parent 14344d0 commit 266c902

File tree

14 files changed

+51
-51
lines changed

14 files changed

+51
-51
lines changed

docs/reference/api-conventions/blocking-async.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ API clients come in two flavors: blocking and asynchronous. All methods on async
99

1010
Both flavors can be used at the same time depending on your needs, sharing the same transport object:
1111

12-
% :::include-code src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=blocking-and-async
12+
% :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=blocking-and-async
1313
```java
1414
// Synchronous blocking client
1515
ElasticsearchClient client = new ElasticsearchClient(transport);

docs/reference/api-conventions/building-objects.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mapped_pages:
1010

1111
All data types in the Java API Client are immutable. Object creation uses the [builder pattern](https://www.informit.com/articles/article.aspx?p=1216151&seqNum=2) that was popularized in **Effective Java** in 2008.
1212

13-
% :::include-code src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=builders
13+
% :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=builders
1414
```java
1515
ElasticsearchClient client = createClient();
1616
CreateIndexResponse createResponse = client.indices().create(
@@ -30,7 +30,7 @@ Note that a builder should not be reused after its `build()` method has been cal
3030

3131
Although this works nicely, having to instantiate builder classes and call the `build()` method is a bit verbose. So every property setter in the Java API Client also accepts a lambda expression that takes a newly created builder as a parameter and returns a populated builder. The snippet above can also be written as:
3232

33-
% :::include-code src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=builder-lambdas
33+
% :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=builder-lambdas
3434
```java
3535
ElasticsearchClient client = createClient();
3636
CreateIndexResponse createResponse = client.indices()
@@ -46,7 +46,7 @@ This approach allows for much more concise code, and also avoids importing class
4646

4747
Note in the above example that builder variables are only used to start a chain of property setters. The names of these variables are therefore unimportant and can be shortened to improve readability:
4848

49-
% :::include-code src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=builder-lambdas-short
49+
% :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=builder-lambdas-short
5050
```java
5151
ElasticsearchClient client = createClient();
5252
CreateIndexResponse createResponse = client.indices()
@@ -62,7 +62,7 @@ Builder lambdas become particularly useful with complex nested queries like the
6262

6363
This example also highlights a useful naming convention for builder parameters in deeply nested structures. For lambda expressions with a single argument, Kotlin provides the implicit `it` parameter and Scala allows use of `_`. This can be approximated in Java by using an underscore or a single letter prefix followed by a number representing the depth level (i.e. `_0`, `_1`, or `b0`, `b1` and so on). Not only does this remove the need to create throw-away variable names, but it also improves code readability. Correct indentation also allows the structure of the query to stand out.
6464

65-
% :::include-code src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=builder-intervals
65+
% :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=builder-intervals
6666
```java
6767
ElasticsearchClient client = createClient();
6868
SearchResponse<SomeApplicationData> results = client

docs/reference/api-conventions/lists-maps.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Properties of type `List` and `Map` are exposed by object builders as a set of o
1212

1313
Object builders create immutable objects, and this also applies to list and map properties that are made immutable at object construction time.
1414

15-
% :::include-code src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=collections
15+
% :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=collections
1616
```java
1717
// Prepare a list of index names
1818
List<String> names = Arrays.asList("idx-a", "idx-b", "idx-c");
@@ -57,7 +57,7 @@ For lists and maps however, applications often only care about whether they’re
5757

5858
If you ever need to distinguish between a missing (undefined) optional collection and an effectively-empty collection returned by {{es}}, the `ApiTypeHelper` class provides a utility method to distinguish them:
5959

60-
% :::include-code src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=optional-collections
60+
% :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=optional-collections
6161
```java
6262
NodeStatistics stats = NodeStatistics.of(b -> b
6363
.total(1)

docs/reference/api-conventions/loading-json.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Consider a resource file `some-index.json` containing an index definition:
3131

3232
You can create an index from that definition as follows:
3333

34-
% :::include-code src={{doc-tests-src}}/api_conventions/LoadingJsonTest.java tag=load-index
34+
% :::{include-code} src={{doc-tests-src}}/api_conventions/LoadingJsonTest.java tag=load-index
3535
```java
3636
InputStream input = this.getClass()
3737
.getResourceAsStream("some-index.json"); // <1>
@@ -53,7 +53,7 @@ boolean created = client.indices().create(req).acknowledged();
5353

5454
Similarly, you can read documents to be stored in {{es}} from data files:
5555

56-
% :::include-code src={{doc-tests-src}}/api_conventions/LoadingJsonTest.java tag=ingest-data
56+
% :::{include-code} src={{doc-tests-src}}/api_conventions/LoadingJsonTest.java tag=ingest-data
5757
```java
5858
FileReader file = new FileReader(new File(dataDir, "document-1.json"));
5959

@@ -75,7 +75,7 @@ client.index(req);
7575

7676
You can combine `withJson()` with regular calls to setter methods. The example below loads the query part of a search request from a `String` and programmatically adds an aggregation.
7777

78-
% :::include-code src={{doc-tests-src}}/api_conventions/LoadingJsonTest.java tag=query
78+
% :::{include-code} src={{doc-tests-src}}/api_conventions/LoadingJsonTest.java tag=query
7979
```java
8080
Reader queryJson = new StringReader(
8181
"{" +
@@ -117,7 +117,7 @@ Map<String, Aggregate> aggs = client
117117

118118
The `withJson()` methods are partial deserializers: the properties loaded from the JSON will set property values or replace the previous ones, but will not reset other properties not found in the JSON input. You can use this to combine multiple JSON snippets to build complex search requests. In the example below, we combine separate definitions of a query that selects some documents and an aggregation that is run on the results of this query.
119119

120-
% :::include-code src={{doc-tests-src}}/api_conventions/LoadingJsonTest.java tag=query-and-agg
120+
% :::{include-code} src={{doc-tests-src}}/api_conventions/LoadingJsonTest.java tag=query-and-agg
121121
```java
122122
Reader queryJson = new StringReader(
123123
"{" +

docs/reference/api-conventions/variant-types.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This is because variant objects in the Java API Client are implementations of a
1313

1414
Variant builders have setter methods for every available implementation. They use the same conventions as regular properties and accept both a builder lambda expression and a ready-made object of the actual type of the variant. Here’s an example to build a term query:
1515

16-
% :::include-code src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=variant-creation
16+
% :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=variant-creation
1717
```java
1818
Query query = new Query.Builder()
1919
.term(t -> t // <1>
@@ -30,7 +30,7 @@ Query query = new Query.Builder()
3030

3131
Variant objects have getter methods for every available implementation. These methods check that the object actually holds a variant of that kind and return the value downcasted to the correct type. They throw an `IllegalStateException` otherwise. This approach allows writing fluent code to traverse variants.
3232

33-
% :::include-code src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=variant-navigation
33+
% :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=variant-navigation
3434
```java
3535
assertEquals("foo", query.term().value().stringValue());
3636
```
@@ -42,7 +42,7 @@ Variant objects also provide information on the variant kind they currently hold
4242

4343
This information can then be used to navigate down into specific variants after checking their actual kind:
4444

45-
% :::include-code src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=variant-kind
45+
% :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=variant-kind
4646
```java
4747
if (query.isTerm()) { // <1>
4848
doSomething(query.term());
@@ -74,7 +74,7 @@ In the examples below we use a hypothetical plugin that adds a `sphere-distance`
7474

7575
To create a custom aggregation, use the `_custom()` aggregation type and provide its identifier, defined by the plugin, and parameters. The parameters can be any object or value that can be serialized to JSON. In the example below we use a simple map:
7676

77-
% :::include-code src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=custom-variant-creation
77+
% :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=custom-variant-creation
7878
```java
7979
Map<String, Object> params = new HashMap<>(); // <1>
8080
params.put("interval", 10);
@@ -97,7 +97,7 @@ The results of custom variants are returned as raw JSON represented by a `JsonDa
9797

9898
Traversing the JSON tree:
9999

100-
% :::include-code src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=custom-variant-navigation-json
100+
% :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=custom-variant-navigation-json
101101
```java
102102
SearchResponse<Void> response = esClient.search(request, Void.class); // <1>
103103

@@ -124,7 +124,7 @@ for (JsonValue item : buckets) {
124124

125125
Using a class that represents the custom aggregation results:
126126

127-
% :::include-code src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=custom-variant-navigation-typed
127+
% :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=custom-variant-navigation-typed
128128
```java
129129
SearchResponse<Void> response = esClient.search(request, Void.class);
130130

@@ -143,7 +143,7 @@ for (Bucket bucket : neighbors.buckets()) {
143143

144144
Where `SphereDistanceAggregate` can be defined as follows:
145145

146-
% :::include-code src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=custom-variant-types
146+
% :::{include-code} src={{doc-tests-src}}/api_conventions/ApiConventionsTest.java tag=custom-variant-types
147147
```java
148148
public static class SphereDistanceAggregate {
149149
private final List<Bucket> buckets;

docs/reference/getting-started.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Refer to the [Installation](setup/installation.md) page to learn more.
5151

5252
You can connect to the Elastic Cloud using an API key and the Elasticsearch endpoint.
5353

54-
% :::include-code src={{doc-tests-src}}/getting_started/ConnectingTest.java tag=create-client
54+
% :::{include-code} src={{doc-tests-src}}/getting_started/ConnectingTest.java tag=create-client
5555
```java
5656
// URL and API key
5757
String serverUrl = "https://localhost:9200";
@@ -94,7 +94,7 @@ Time to use Elasticsearch! This section walks you through the basic, and most im
9494

9595
This is how you create the `product` index:
9696

97-
% :::include-code src={{doc-tests-src}}/usage/IndexingTest.java tag=create-products-index
97+
% :::{include-code} src={{doc-tests-src}}/usage/IndexingTest.java tag=create-products-index
9898
```java
9999
esClient.indices().create(c -> c
100100
.index("products")
@@ -106,7 +106,7 @@ esClient.indices().create(c -> c
106106

107107
This is a simple way of indexing a document, here a `Product` application object:
108108

109-
% :::include-code src={{doc-tests-src}}/usage/IndexingTest.java tag=single-doc-dsl
109+
% :::{include-code} src={{doc-tests-src}}/usage/IndexingTest.java tag=single-doc-dsl
110110
```java
111111
Product product = new Product("bk-1", "City bike", 123.0);
112112

@@ -123,7 +123,7 @@ logger.info("Indexed with version " + response.version());
123123

124124
You can get documents by using the following code:
125125

126-
% :::include-code src={{doc-tests-src}}/usage/ReadingTest.java tag=get-by-id
126+
% :::{include-code} src={{doc-tests-src}}/usage/ReadingTest.java tag=get-by-id
127127
```java
128128
GetResponse<Product> response = esClient.get(g -> g
129129
.index("products") // <1>
@@ -146,7 +146,7 @@ if (response.found()) {
146146

147147
This is how you can create a single match query with the Java client:
148148

149-
% :::include-code src={{doc-tests-src}}/usage/SearchingTest.java tag=search-getting-started
149+
% :::{include-code} src={{doc-tests-src}}/usage/SearchingTest.java tag=search-getting-started
150150
```java
151151
String searchText = "bike";
152152

@@ -166,7 +166,7 @@ SearchResponse<Product> response = esClient.search(s -> s
166166

167167
This is how you can update a document, for example to add a new field:
168168

169-
% :::include-code src={{doc-tests-src}}/usage/IndexingTest.java tag=single-doc-update
169+
% :::{include-code} src={{doc-tests-src}}/usage/IndexingTest.java tag=single-doc-update
170170
```java
171171
Product product = new Product("bk-1", "City bike", 123.0);
172172

@@ -180,14 +180,14 @@ esClient.update(u -> u
180180

181181
#### Deleting documents [_deleting_documents]
182182

183-
% :::include-code src={{doc-tests-src}}/usage/IndexingTest.java tag=single-doc-delete
183+
% :::{include-code} src={{doc-tests-src}}/usage/IndexingTest.java tag=single-doc-delete
184184
```java
185185
esClient.delete(d -> d.index("products").id("bk-1"));
186186
```
187187

188188
#### Deleting an index [_deleting_an_index]
189189

190-
% :::include-code src={{doc-tests-src}}/usage/IndexingTest.java tag=delete-products-index
190+
% :::{include-code} src={{doc-tests-src}}/usage/IndexingTest.java tag=delete-products-index
191191
```java
192192
esClient.indices().delete(d -> d
193193
.index("products")

docs/reference/setup/connecting.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The Java API Client is structured around three main components:
1313

1414
This code snippet creates and wires together these three components:
1515

16-
% :::include-code src={{doc-tests-src}}/getting_started/ConnectingTest.java tag=create-client
16+
% :::{include-code} src={{doc-tests-src}}/getting_started/ConnectingTest.java tag=create-client
1717
```java
1818
// URL and API key
1919
String serverUrl = "https://localhost:9200";
@@ -41,7 +41,7 @@ The code snippet below searches all items from a “product” index whose name
4141

4242
It illustrates the use of fluent functional builders to write search queries as concise DSL-like code. This pattern is explained in more detail in [*API conventions*](/reference/api-conventions/index.md).
4343

44-
% :::include-code src={{doc-tests-src}}/getting_started/ConnectingTest.java tag=first-request
44+
% :::{include-code} src={{doc-tests-src}}/getting_started/ConnectingTest.java tag=first-request
4545
```java
4646
SearchResponse<Product> search = esClient.search(s -> s
4747
.index("products")
@@ -86,7 +86,7 @@ Depending on the context, you have two options for verifying the HTTPS connectio
8686

8787
This method of verifying the HTTPS connection uses the certificate fingerprint value noted down earlier.
8888

89-
% :::include-code src={{doc-tests-src}}/getting_started/ConnectingTest.java tag=create-secure-client-fingerprint
89+
% :::{include-code} src={{doc-tests-src}}/getting_started/ConnectingTest.java tag=create-secure-client-fingerprint
9090
```java
9191
String fingerprint = "<certificate fingerprint>";
9292

@@ -131,7 +131,7 @@ The generated root CA certificate can be found in the `certs` directory in your
131131

132132
Once you have made the `http_ca.crt` file available to your application, you can use it to set up the client:
133133

134-
% :::include-code src={{doc-tests-src}}/getting_started/ConnectingTest.java tag=create-secure-client-cert
134+
% :::{include-code} src={{doc-tests-src}}/getting_started/ConnectingTest.java tag=create-secure-client-cert
135135
```java
136136
File certFile = new File("/path/to/http_ca.crt");
137137

docs/reference/setup/opentelemetry.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ When using the [OpenTelemetry Java SDK manually](https://opentelemetry.io/docs/i
4040

4141
In case you are using [manual OpenTelemetry instrumentation](https://opentelemetry.io/docs/instrumentation/java/manual/#example) with a custom OpenTelemetry SDK instance that is *not registered globally*, you can create the Java API Client using a custom OpenTelemetry instance. The following code snippet shows an example of using a custom OpenTelemetry instance.
4242

43-
% :::include-code src={{doc-tests-src}}/getting_started/ConnectingTest.java tag=create-client-otel
43+
% :::{include-code} src={{doc-tests-src}}/getting_started/ConnectingTest.java tag=create-client-otel
4444
```java
4545
// URL and API key
4646
String serverUrl = "https://localhost:9200";

docs/reference/usage/aggregations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This example is an analytics-type aggregation where we do not want to use the ma
2121

2222
If that same aggregation was used for to display products and the price histogram as drill-down facets, we would have set `size` to a non-zero value and used `Product` as the target class to process the results.
2323

24-
% :::include-code src={{doc-tests-src}}/usage/AggregationsTest.java tag=price-histo-request
24+
% :::{include-code} src={{doc-tests-src}}/usage/AggregationsTest.java tag=price-histo-request
2525
```java
2626
String searchText = "bike";
2727

@@ -53,7 +53,7 @@ SearchResponse<Void> response = esClient.search(b -> b
5353

5454
The response contains an aggregation result for each aggregation in the request.
5555

56-
% :::include-code src={{doc-tests-src}}/usage/AggregationsTest.java tag=price-histo-response
56+
% :::{include-code} src={{doc-tests-src}}/usage/AggregationsTest.java tag=price-histo-response
5757
```java
5858
List<HistogramBucket> buckets = response.aggregations()
5959
.get("price-histogram") // <1>

docs/reference/usage/indexing-bulk.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ A `BulkRequest` contains a collection of operations, each operation being a [typ
2424

2525
The example below shows how to index a list or application objects.
2626

27-
% :::include-code src={{doc-tests-src}}/usage/IndexingBulkTest.java tag=bulk-objects
27+
% :::{include-code} src={{doc-tests-src}}/usage/IndexingBulkTest.java tag=bulk-objects
2828
```java
2929
List<Product> products = fetchProducts();
3030

@@ -63,7 +63,7 @@ The `document` property of a bulk index request can be any object that can be se
6363

6464
In the example below we will use the Java API Client’s `BinaryData` to read json files from a log directory and send them in a bulk request.
6565

66-
% :::include-code src={{doc-tests-src}}/usage/IndexingBulkTest.java tag=bulk-json
66+
% :::{include-code} src={{doc-tests-src}}/usage/IndexingBulkTest.java tag=bulk-json
6767
```java
6868
// List json log files in the log directory
6969
File[] logFiles = logDir.listFiles(
@@ -97,7 +97,7 @@ The ingester will send a bulk request when one of the following criteria is met:
9797

9898
Additionally, you can define a maximum number of concurrent request waiting to be executed by {{es}} (defaults to 1). When that maximum is reached and the maximum number of operations have been collected, adding a new operation to the indexer will block. This is avoids overloading the {{es}} server by putting backpressure on the client application.
9999

100-
% :::include-code src={{doc-tests-src}}/usage/IndexingBulkTest.java tag=bulk-ingester-setup
100+
% :::{include-code} src={{doc-tests-src}}/usage/IndexingBulkTest.java tag=bulk-ingester-setup
101101
```java
102102
BulkIngester<Void> ingester = BulkIngester.of(b -> b
103103
.client(esClient) // <1>
@@ -131,7 +131,7 @@ Additionally, the bulk ingester accepts a listener so that your application can
131131

132132
The following example shows how you can use context values to implement a bulk ingestion listener: as previously it sends JSON log files in bulk, but tracks bulk request errors and failed operations. When an operation fails, depending on the error type you may want to re-add it to the ingester.
133133

134-
% :::include-code src={{doc-tests-src}}/usage/IndexingBulkTest.java tag=bulk-ingester-context
134+
% :::{include-code} src={{doc-tests-src}}/usage/IndexingBulkTest.java tag=bulk-ingester-context
135135
```java
136136
BulkListener<String> listener = new BulkListener<String>() { // <1>
137137
@Override

0 commit comments

Comments
 (0)