Skip to content

Commit 6ae3149

Browse files
authored
Merge branch 'main' into add.documentation
2 parents 79c3854 + 5c7c24d commit 6ae3149

File tree

645 files changed

+10071
-8161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

645 files changed

+10071
-8161
lines changed

java-client/src/main/java/co/elastic/clients/base/ApiException.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

java-client/src/main/java/co/elastic/clients/base/SimpleEndpoint.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919

2020
package co.elastic.clients.base;
2121

22+
import co.elastic.clients.elasticsearch._types.ErrorResponse;
2223
import co.elastic.clients.json.JsonpDeserializer;
2324
import org.apache.http.client.utils.URLEncodedUtils;
2425

2526
import java.util.Collections;
2627
import java.util.Map;
2728
import java.util.function.Function;
2829

29-
public class SimpleEndpoint<RequestT, ResponseT> implements Endpoint<RequestT, ResponseT, ElasticsearchError> {
30+
public class SimpleEndpoint<RequestT, ResponseT> implements Endpoint<RequestT, ResponseT, ErrorResponse> {
3031

3132
private static final Function<?, Map<String, String>> EMPTY_MAP = x -> Collections.emptyMap();
3233

@@ -99,8 +100,8 @@ public boolean isError(int statusCode) {
99100
}
100101

101102
@Override
102-
public JsonpDeserializer<ElasticsearchError> errorParser(int statusCode) {
103-
return ElasticsearchError._DESERIALIZER;
103+
public JsonpDeserializer<ErrorResponse> errorParser(int statusCode) {
104+
return ErrorResponse._DESERIALIZER;
104105
}
105106

106107
public <NewResponseT> SimpleEndpoint<RequestT, NewResponseT> withResponseDeserializer(

java-client/src/main/java/co/elastic/clients/base/rest_client/RestClientTransport.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919

2020
package co.elastic.clients.base.rest_client;
2121

22-
import co.elastic.clients.base.ApiException;
2322
import co.elastic.clients.base.BooleanEndpoint;
2423
import co.elastic.clients.base.BooleanResponse;
2524
import co.elastic.clients.base.ElasticsearchCatRequest;
25+
import co.elastic.clients.elasticsearch.ElasticsearchException;
2626
import co.elastic.clients.base.Endpoint;
2727
import co.elastic.clients.base.Transport;
28+
import co.elastic.clients.elasticsearch._types.ErrorResponse;
2829
import co.elastic.clients.json.JsonpDeserializer;
2930
import co.elastic.clients.json.JsonpMapper;
3031
import co.elastic.clients.json.NdJsonpSerializable;
@@ -43,6 +44,7 @@
4344
import java.io.ByteArrayOutputStream;
4445
import java.io.IOException;
4546
import java.io.InputStream;
47+
import java.util.Iterator;
4648
import java.util.Map;
4749
import java.util.concurrent.CompletableFuture;
4850
import java.util.function.Function;
@@ -168,8 +170,8 @@ private <RequestT> org.elasticsearch.client.Request prepareLowLevelRequest(
168170
// Request has a body and must implement JsonpSerializable or NdJsonpSerializable
169171
ByteArrayOutputStream baos = new ByteArrayOutputStream();
170172

171-
if (request instanceof NdJsonpSerializable<?>) {
172-
writeNdJson((NdJsonpSerializable<?>) request, baos);
173+
if (request instanceof NdJsonpSerializable) {
174+
writeNdJson((NdJsonpSerializable) request, baos);
173175
} else {
174176
JsonGenerator generator = mapper.jsonProvider().createGenerator(baos);
175177
mapper.serialize(request, generator);
@@ -184,15 +186,15 @@ private <RequestT> org.elasticsearch.client.Request prepareLowLevelRequest(
184186
}
185187

186188
/**
187-
* Write an nd-json value by serializing each of its items on a separate line.
188-
* <p>
189-
* If an item itself implements {@link NdJsonpSerializable}, it is output as nd-json. This allows flattening
190-
* nested structures.
189+
* Write an nd-json value by serializing each of its items on a separate line, recursing if its items themselves implement
190+
* {@link NdJsonpSerializable} to flattening nested structures.
191191
*/
192-
private void writeNdJson(NdJsonpSerializable<?> value, ByteArrayOutputStream baos) {
193-
for (Object item: value) {
194-
if (item instanceof NdJsonpSerializable<?>) {
195-
writeNdJson((NdJsonpSerializable<?>) item, baos);
192+
private void writeNdJson(NdJsonpSerializable value, ByteArrayOutputStream baos) {
193+
Iterator<?> values = value._serializables();
194+
while(values.hasNext()) {
195+
Object item = values.next();
196+
if (item instanceof NdJsonpSerializable && item != value) { // do not recurse on the item itself
197+
writeNdJson((NdJsonpSerializable) item, baos);
196198
} else {
197199
JsonGenerator generator = mapper.jsonProvider().createGenerator(baos);
198200
mapper.serialize(item, generator);
@@ -221,7 +223,8 @@ private <ResponseT, ErrorT> ResponseT getHighLevelResponse(
221223
error = errorParser.deserialize(parser, mapper);
222224
}
223225

224-
throw new ApiException(error);
226+
// TODO: have the endpoint provide the exception contructor
227+
throw new ElasticsearchException((ErrorResponse) error);
225228

226229
} else if (endpoint instanceof BooleanEndpoint) {
227230
BooleanEndpoint<?> bep = (BooleanEndpoint<?>)endpoint;

java-client/src/main/java/co/elastic/clients/elasticsearch/ElasticsearchAsyncClient.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public ElasticsearchXpackAsyncClient xpack() {
291291
* on elastic.co</a>
292292
*/
293293

294-
public <TSource> CompletableFuture<BulkResponse> bulk(BulkRequest<TSource> request) throws IOException {
294+
public CompletableFuture<BulkResponse> bulk(BulkRequest request) throws IOException {
295295
return this.transport.performRequestAsync(request, BulkRequest.ENDPOINT);
296296
}
297297

@@ -308,9 +308,22 @@ public <TSource> CompletableFuture<BulkResponse> bulk(BulkRequest<TSource> reque
308308
* on elastic.co</a>
309309
*/
310310

311-
public final <TSource> CompletableFuture<BulkResponse> bulk(
312-
Function<BulkRequest.Builder<TSource>, ObjectBuilder<BulkRequest<TSource>>> fn) throws IOException {
313-
return bulk(fn.apply(new BulkRequest.Builder<TSource>()).build());
311+
public final CompletableFuture<BulkResponse> bulk(Function<BulkRequest.Builder, ObjectBuilder<BulkRequest>> fn)
312+
throws IOException {
313+
return bulk(fn.apply(new BulkRequest.Builder()).build());
314+
}
315+
316+
/**
317+
* Allows to perform multiple index/update/delete operations in a single
318+
* request.
319+
*
320+
* @see <a href=
321+
* "https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html">Documentation
322+
* on elastic.co</a>
323+
*/
324+
325+
public CompletableFuture<BulkResponse> bulk() throws IOException {
326+
return this.transport.performRequestAsync(new BulkRequest.Builder().build(), BulkRequest.ENDPOINT);
314327
}
315328

316329
// ----- Endpoint: clear_scroll
@@ -813,7 +826,7 @@ public final CompletableFuture<GetScriptResponse> getScript(
813826
* "https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-contexts.html">Documentation
814827
* on elastic.co</a>
815828
*/
816-
public CompletableFuture<GetScriptContextResponse> getScriptContext() throws IOException {
829+
public CompletableFuture<GetScriptContextResponse> getScriptContext() throws IOException, ElasticsearchException {
817830
return this.transport.performRequestAsync(GetScriptContextRequest._INSTANCE, GetScriptContextRequest.ENDPOINT);
818831
}
819832

@@ -826,7 +839,8 @@ public CompletableFuture<GetScriptContextResponse> getScriptContext() throws IOE
826839
* "https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html">Documentation
827840
* on elastic.co</a>
828841
*/
829-
public CompletableFuture<GetScriptLanguagesResponse> getScriptLanguages() throws IOException {
842+
public CompletableFuture<GetScriptLanguagesResponse> getScriptLanguages()
843+
throws IOException, ElasticsearchException {
830844
return this.transport.performRequestAsync(GetScriptLanguagesRequest._INSTANCE,
831845
GetScriptLanguagesRequest.ENDPOINT);
832846
}
@@ -905,7 +919,7 @@ public final <TDocument> CompletableFuture<IndexResponse> index(
905919
* "https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html">Documentation
906920
* on elastic.co</a>
907921
*/
908-
public CompletableFuture<InfoResponse> info() throws IOException {
922+
public CompletableFuture<InfoResponse> info() throws IOException, ElasticsearchException {
909923
return this.transport.performRequestAsync(InfoRequest._INSTANCE, InfoRequest.ENDPOINT);
910924
}
911925

@@ -1096,7 +1110,7 @@ public final CompletableFuture<OpenPointInTimeResponse> openPointInTime(
10961110
* "https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html">Documentation
10971111
* on elastic.co</a>
10981112
*/
1099-
public CompletableFuture<BooleanResponse> ping() throws IOException {
1113+
public CompletableFuture<BooleanResponse> ping() throws IOException, ElasticsearchException {
11001114
return this.transport.performRequestAsync(PingRequest._INSTANCE, PingRequest.ENDPOINT);
11011115
}
11021116

java-client/src/main/java/co/elastic/clients/elasticsearch/ElasticsearchClient.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public ElasticsearchXpackClient xpack() {
290290
* on elastic.co</a>
291291
*/
292292

293-
public <TSource> BulkResponse bulk(BulkRequest<TSource> request) throws IOException {
293+
public BulkResponse bulk(BulkRequest request) throws IOException {
294294
return this.transport.performRequest(request, BulkRequest.ENDPOINT);
295295
}
296296

@@ -307,9 +307,21 @@ public <TSource> BulkResponse bulk(BulkRequest<TSource> request) throws IOExcept
307307
* on elastic.co</a>
308308
*/
309309

310-
public final <TSource> BulkResponse bulk(
311-
Function<BulkRequest.Builder<TSource>, ObjectBuilder<BulkRequest<TSource>>> fn) throws IOException {
312-
return bulk(fn.apply(new BulkRequest.Builder<TSource>()).build());
310+
public final BulkResponse bulk(Function<BulkRequest.Builder, ObjectBuilder<BulkRequest>> fn) throws IOException {
311+
return bulk(fn.apply(new BulkRequest.Builder()).build());
312+
}
313+
314+
/**
315+
* Allows to perform multiple index/update/delete operations in a single
316+
* request.
317+
*
318+
* @see <a href=
319+
* "https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html">Documentation
320+
* on elastic.co</a>
321+
*/
322+
323+
public BulkResponse bulk() throws IOException {
324+
return this.transport.performRequest(new BulkRequest.Builder().build(), BulkRequest.ENDPOINT);
313325
}
314326

315327
// ----- Endpoint: clear_scroll
@@ -808,7 +820,7 @@ public final GetScriptResponse getScript(Function<GetScriptRequest.Builder, Obje
808820
* "https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-contexts.html">Documentation
809821
* on elastic.co</a>
810822
*/
811-
public GetScriptContextResponse getScriptContext() throws IOException {
823+
public GetScriptContextResponse getScriptContext() throws IOException, ElasticsearchException {
812824
return this.transport.performRequest(GetScriptContextRequest._INSTANCE, GetScriptContextRequest.ENDPOINT);
813825
}
814826

@@ -821,7 +833,7 @@ public GetScriptContextResponse getScriptContext() throws IOException {
821833
* "https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html">Documentation
822834
* on elastic.co</a>
823835
*/
824-
public GetScriptLanguagesResponse getScriptLanguages() throws IOException {
836+
public GetScriptLanguagesResponse getScriptLanguages() throws IOException, ElasticsearchException {
825837
return this.transport.performRequest(GetScriptLanguagesRequest._INSTANCE, GetScriptLanguagesRequest.ENDPOINT);
826838
}
827839

@@ -899,7 +911,7 @@ public final <TDocument> IndexResponse index(
899911
* "https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html">Documentation
900912
* on elastic.co</a>
901913
*/
902-
public InfoResponse info() throws IOException {
914+
public InfoResponse info() throws IOException, ElasticsearchException {
903915
return this.transport.performRequest(InfoRequest._INSTANCE, InfoRequest.ENDPOINT);
904916
}
905917

@@ -1086,7 +1098,7 @@ public final OpenPointInTimeResponse openPointInTime(
10861098
* "https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html">Documentation
10871099
* on elastic.co</a>
10881100
*/
1089-
public BooleanResponse ping() throws IOException {
1101+
public BooleanResponse ping() throws IOException, ElasticsearchException {
10901102
return this.transport.performRequest(PingRequest._INSTANCE, PingRequest.ENDPOINT);
10911103
}
10921104

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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;
21+
22+
import co.elastic.clients.elasticsearch._types.ErrorCause;
23+
import co.elastic.clients.elasticsearch._types.ErrorResponse;
24+
25+
/**
26+
* Exception thrown by API client methods when Elasticsearch could not accept or process a request.
27+
* <p>
28+
* The {@link #error()} contains the error's type and reason along with additional details that depend on the error type and
29+
* the API endpoint that was called.
30+
*/
31+
public class ElasticsearchException extends RuntimeException {
32+
33+
private final ErrorResponse response;
34+
35+
public ElasticsearchException(ErrorResponse response) {
36+
super(response.error().reason());
37+
this.response = response;
38+
}
39+
40+
/**
41+
* The error response sent by Elasticsearch
42+
*/
43+
public ErrorResponse response() {
44+
return this.response;
45+
}
46+
47+
/**
48+
* The cause of the error. Shortcut for {@code response().error()}.
49+
*/
50+
public ErrorCause error() {
51+
return this.response.error();
52+
}
53+
54+
/**
55+
* Status code returned by Elasticsearch. Shortcut for {@code response().status()}.
56+
*/
57+
public int status() {
58+
return this.response.status();
59+
}
60+
}

java-client/src/main/java/co/elastic/clients/elasticsearch/_types/BulkIndexByScrollFailure.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
// typedef: _types.BulkIndexByScrollFailure
4242
@JsonpDeserializable
4343
public final class BulkIndexByScrollFailure implements JsonpSerializable {
44-
private final MainError cause;
44+
private final ErrorCause cause;
4545

4646
private final String id;
4747

@@ -70,7 +70,7 @@ public BulkIndexByScrollFailure(Function<Builder, Builder> fn) {
7070
/**
7171
* Required - API name: {@code cause}
7272
*/
73-
public MainError cause() {
73+
public ErrorCause cause() {
7474
return this.cause;
7575
}
7676

@@ -136,7 +136,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
136136
* Builder for {@link BulkIndexByScrollFailure}.
137137
*/
138138
public static class Builder implements ObjectBuilder<BulkIndexByScrollFailure> {
139-
private MainError cause;
139+
private ErrorCause cause;
140140

141141
private String id;
142142

@@ -149,16 +149,16 @@ public static class Builder implements ObjectBuilder<BulkIndexByScrollFailure> {
149149
/**
150150
* Required - API name: {@code cause}
151151
*/
152-
public Builder cause(MainError value) {
152+
public Builder cause(ErrorCause value) {
153153
this.cause = value;
154154
return this;
155155
}
156156

157157
/**
158158
* Required - API name: {@code cause}
159159
*/
160-
public Builder cause(Function<MainError.Builder, ObjectBuilder<MainError>> fn) {
161-
return this.cause(fn.apply(new MainError.Builder()).build());
160+
public Builder cause(Function<ErrorCause.Builder, ObjectBuilder<ErrorCause>> fn) {
161+
return this.cause(fn.apply(new ErrorCause.Builder()).build());
162162
}
163163

164164
/**
@@ -216,7 +216,7 @@ public BulkIndexByScrollFailure build() {
216216
protected static void setupBulkIndexByScrollFailureDeserializer(
217217
DelegatingDeserializer<BulkIndexByScrollFailure.Builder> op) {
218218

219-
op.add(Builder::cause, MainError._DESERIALIZER, "cause");
219+
op.add(Builder::cause, ErrorCause._DESERIALIZER, "cause");
220220
op.add(Builder::id, JsonpDeserializer.stringDeserializer(), "id");
221221
op.add(Builder::index, JsonpDeserializer.stringDeserializer(), "index");
222222
op.add(Builder::status, JsonpDeserializer.integerDeserializer(), "status");

0 commit comments

Comments
 (0)