Class ElasticsearchIO.ConnectionConfiguration
java.lang.Object
org.apache.beam.sdk.io.elasticsearch.ElasticsearchIO.ConnectionConfiguration
- All Implemented Interfaces:
Serializable
- Enclosing class:
ElasticsearchIO
public abstract static class ElasticsearchIO.ConnectionConfiguration
extends Object
implements Serializable
A POJO describing a connection configuration to Elasticsearch.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates a new Elasticsearch connection configuration with no default index nor type.Creates a new Elasticsearch connection configuration with no default type.Creates a new Elasticsearch connection configuration.Generates the API endpoint prefix based on the set values.abstract String
getIndex()
getPrefixedEndpoint
(String endpoint) getType()
abstract boolean
abstract boolean
withApiKey
(String apiKey) If Elasticsearch authentication is enabled, provide an API key.withBearerToken
(String bearerToken) If Elasticsearch authentication is enabled, provide a bearer token.withCompressionEnabled
(boolean compressionEnabled) Configure whether the REST client should compress requests using gzip content encoding and add the "Accept-Encoding: gzip".withConnectTimeout
(Integer connectTimeout) If set, overwrites the default connect timeout (1000ms) in theRequestConfig
of the ElasticRestClient
.withDefaultHeaders
(Header[] defaultHeaders) For authentication or custom requirements, provide a set if default headers for the client.withKeystorePassword
(String keystorePassword) If Elasticsearch uses SSL/TLS with mutual authentication (via shield), provide the password to open the client keystore.withKeystorePath
(String keystorePath) If Elasticsearch uses SSL/TLS with mutual authentication (via shield), provide the keystore containing the client key.withPassword
(String password) If Elasticsearch authentication is enabled, provide the password.withPathPrefix
(String pathPrefix) If Elasticsearch is not running at the root path, e.g.withSocketTimeout
(Integer socketTimeout) If set, overwrites the default max retry timeout (30000ms) in the ElasticRestClient
and the default socket timeout (30000ms) in theRequestConfig
of the ElasticRestClient
.withTrustSelfSignedCerts
(boolean trustSelfSignedCerts) If Elasticsearch uses SSL/TLS then configure whether to trust self signed certs or not.withUsername
(String username) If Elasticsearch authentication is enabled, provide the username.
-
Constructor Details
-
ConnectionConfiguration
public ConnectionConfiguration()
-
-
Method Details
-
getAddresses
-
getUsername
-
getPassword
-
getApiKey
-
getBearerToken
-
getDefaultHeaders
-
getKeystorePath
-
getKeystorePassword
-
getPathPrefix
-
getIndex
-
getType
-
getSocketTimeout
-
getConnectTimeout
-
isTrustSelfSignedCerts
public abstract boolean isTrustSelfSignedCerts() -
isCompressionEnabled
public abstract boolean isCompressionEnabled() -
create
public static ElasticsearchIO.ConnectionConfiguration create(String[] addresses, String index, String type) Creates a new Elasticsearch connection configuration.- Parameters:
addresses
- list of addresses of Elasticsearch nodesindex
- the index toward which the requests will be issuedtype
- the document type toward which the requests will be issued- Returns:
- the connection configuration object
-
create
Creates a new Elasticsearch connection configuration with no default type.- Parameters:
addresses
- list of addresses of Elasticsearch nodesindex
- the index toward which the requests will be issued- Returns:
- the connection configuration object
-
create
Creates a new Elasticsearch connection configuration with no default index nor type.- Parameters:
addresses
- list of addresses of Elasticsearch nodes- Returns:
- the connection configuration object
-
getApiPrefix
Generates the API endpoint prefix based on the set values.Based on ConnectionConfiguration constructors, we know that one of the following is true:
- index and type are non-empty strings
- index is non-empty string, type is empty string
- index and type are empty string
Example valid endpoints therefore include:
- /_bulk
- /index_name/_bulk
- /index_name/type_name/_bulk
-
getPrefixedEndpoint
-
getBulkEndPoint
-
getSearchEndPoint
-
getCountEndPoint
-
withUsername
If Elasticsearch authentication is enabled, provide the username.- Parameters:
username
- the username used to authenticate to Elasticsearch- Returns:
- a
ElasticsearchIO.ConnectionConfiguration
describes a connection configuration to Elasticsearch.
-
withPassword
If Elasticsearch authentication is enabled, provide the password.- Parameters:
password
- the password used to authenticate to Elasticsearch- Returns:
- a
ElasticsearchIO.ConnectionConfiguration
describes a connection configuration to Elasticsearch.
-
withPathPrefix
If Elasticsearch is not running at the root path, e.g. 'host:9200/path/to/index', specify path prefix 'path/to'.- Parameters:
pathPrefix
- the path prefix used in Elasticsearch instance.- Returns:
- a
ElasticsearchIO.ConnectionConfiguration
describes a connection configuration to Elasticsearch.
-
withApiKey
If Elasticsearch authentication is enabled, provide an API key. Be aware that you can only use one of ,withBearerToken()
andwithDefaultHeaders
at the same time, as they (potentially) use the same header.- Parameters:
apiKey
- the API key used to authenticate to Elasticsearch- Returns:
- a
ElasticsearchIO.ConnectionConfiguration
describes a connection configuration to Elasticsearch.
-
withBearerToken
If Elasticsearch authentication is enabled, provide a bearer token. Be aware that you can only use one of ,withBearerToken()
andwithDefaultHeaders
at the same time, as they (potentially) use the same header.- Parameters:
bearerToken
- the bearer token used to authenticate to Elasticsearch- Returns:
- a
ElasticsearchIO.ConnectionConfiguration
describes a connection configuration to Elasticsearch.
-
withDefaultHeaders
For authentication or custom requirements, provide a set if default headers for the client. Be aware that you can only use one ofwithApiToken()
,withBearerToken()
andwithDefaultHeaders
at the same time, as they (potentially) use the same header.An example of where this could be useful is if the client needs to use short-lived credentials that need to be renewed on a certain interval. To implement that, a user could implement a custom header that tracks the renewal period, for example:
class OAuthTokenHeader extends BasicHeader { OAuthToken accessToken; ... @Override public String getValue() { if (accessToken.isExpired()) { accessToken.renew(); } return String.format("Bearer %s", accessToken.getToken()); } }
- Parameters:
defaultHeaders
- the headers to add to outgoing requests- Returns:
- a
ElasticsearchIO.ConnectionConfiguration
describes a connection configuration to Elasticsearch.
-
withKeystorePath
If Elasticsearch uses SSL/TLS with mutual authentication (via shield), provide the keystore containing the client key.- Parameters:
keystorePath
- the location of the keystore containing the client key.- Returns:
- a
ElasticsearchIO.ConnectionConfiguration
describes a connection configuration to Elasticsearch.
-
withKeystorePassword
If Elasticsearch uses SSL/TLS with mutual authentication (via shield), provide the password to open the client keystore.- Parameters:
keystorePassword
- the password of the client keystore.- Returns:
- a
ElasticsearchIO.ConnectionConfiguration
describes a connection configuration to Elasticsearch.
-
withTrustSelfSignedCerts
public ElasticsearchIO.ConnectionConfiguration withTrustSelfSignedCerts(boolean trustSelfSignedCerts) If Elasticsearch uses SSL/TLS then configure whether to trust self signed certs or not. The default is false.- Parameters:
trustSelfSignedCerts
- Whether to trust self signed certs- Returns:
- a
ElasticsearchIO.ConnectionConfiguration
describes a connection configuration to Elasticsearch.
-
withCompressionEnabled
Configure whether the REST client should compress requests using gzip content encoding and add the "Accept-Encoding: gzip". The default is true.- Parameters:
compressionEnabled
- Whether to compress requests using gzip content encoding and add the "Accept-Encoding: gzip"- Returns:
- a
ElasticsearchIO.ConnectionConfiguration
describes a connection configuration to Elasticsearch.
-
withSocketTimeout
If set, overwrites the default max retry timeout (30000ms) in the ElasticRestClient
and the default socket timeout (30000ms) in theRequestConfig
of the ElasticRestClient
.- Parameters:
socketTimeout
- the socket and retry timeout in millis.- Returns:
- a
ElasticsearchIO.ConnectionConfiguration
describes a connection configuration to Elasticsearch.
-
withConnectTimeout
If set, overwrites the default connect timeout (1000ms) in theRequestConfig
of the ElasticRestClient
.- Parameters:
connectTimeout
- the socket and retry timeout in millis.- Returns:
- a
ElasticsearchIO.ConnectionConfiguration
describes a connection configuration to Elasticsearch.
-