forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for rest compatibility headers to the HLRC (elastic#78490)
This adds support for the headers necessary for REST version compatibility to the High Level Rest Client (HLRC). Compatibility mode can be turned on either with the .setAPICompatibilityMode(true) when creating the client, or by setting the ELASTIC_CLIENT_APIVERSIONING to true similar to our other Elasticsearch clients. Resolves elastic#77859
- Loading branch information
Showing
6 changed files
with
338 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...nt/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClientBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.client; | ||
|
||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.core.CheckedConsumer; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Helper to build a {@link RestHighLevelClient}, allowing setting the low-level client that | ||
* should be used as well as whether API compatibility should be used. | ||
*/ | ||
|
||
public class RestHighLevelClientBuilder { | ||
private final RestClient restClient; | ||
private CheckedConsumer<RestClient, IOException> closeHandler = RestClient::close; | ||
private List<NamedXContentRegistry.Entry> namedXContentEntries = Collections.emptyList(); | ||
private Boolean apiCompatibilityMode = null; | ||
|
||
public RestHighLevelClientBuilder(RestClient restClient) { | ||
this.restClient = restClient; | ||
} | ||
|
||
public RestHighLevelClientBuilder closeHandler(CheckedConsumer<RestClient, IOException> closeHandler) { | ||
this.closeHandler = closeHandler; | ||
return this; | ||
} | ||
|
||
public RestHighLevelClientBuilder namedXContentEntries(List<NamedXContentRegistry.Entry> namedXContentEntries) { | ||
this.namedXContentEntries = namedXContentEntries; | ||
return this; | ||
} | ||
|
||
public RestHighLevelClientBuilder setApiCompatibilityMode(Boolean enabled) { | ||
this.apiCompatibilityMode = enabled; | ||
return this; | ||
} | ||
|
||
public RestHighLevelClient build() { | ||
return new RestHighLevelClient(this.restClient, this.closeHandler, this.namedXContentEntries, this.apiCompatibilityMode); | ||
} | ||
} |
Oops, something went wrong.