T
- public final class ElasticSinkBuilder<T> extends Object implements Serializable
The Sink first maps items from the pipeline using the provided
mapToRequestFn(FunctionEx)
and then using BulkRequest
.
BulkRequest()
is used by default, it can be
modified by providing custom bulkRequestFn(SupplierEx)
Usage:
Sink<Map<String, ?>> elasticSink = new ElasticSinkBuilder<Map<String, ?>>()
.clientFn(() -> ElasticClients.client(host, port))
.mapToRequestFn(item -> new IndexRequest("my-index").source(item))
.build();
Requires clientFn(SupplierEx)
and mapToRequestFn(FunctionEx)
.
Constructor and Description |
---|
ElasticSinkBuilder() |
Modifier and Type | Method and Description |
---|---|
Sink<T> |
build()
Create a sink that writes data into Elasticsearch based on this builder configuration
|
ElasticSinkBuilder<T> |
bulkRequestFn(SupplierEx<org.elasticsearch.action.bulk.BulkRequest> bulkRequestFn)
Set the supplier function for BulkRequest, defaults to new
BulkRequest() |
ElasticSinkBuilder<T> |
clientFn(SupplierEx<org.elasticsearch.client.RestClientBuilder> clientFn)
Set the client supplier function
|
<T_NEW> ElasticSinkBuilder<T_NEW> |
mapToRequestFn(FunctionEx<? super T_NEW,? extends org.elasticsearch.action.DocWriteRequest<?>> mapToRequestFn)
Set the function mapping the item from a pipeline item to an index
request
|
ElasticSinkBuilder<T> |
retries(int retries)
Number of retries the connector will do in addition to Elastic client
retries
Elastic client tries to connect to a node only once for each request.
|
@Nonnull public ElasticSinkBuilder<T> clientFn(@Nonnull SupplierEx<org.elasticsearch.client.RestClientBuilder> clientFn)
The connector uses the returned instance to access Elasticsearch.
Also see ElasticClients
for convenience
factory methods.
For example, to provide an authenticated client:
builder.clientFn(() -> client(host, port, username, password))
This parameter is required.clientFn
- supplier function returning configured Elasticsearch
REST client@Nonnull public ElasticSinkBuilder<T> bulkRequestFn(@Nonnull SupplierEx<org.elasticsearch.action.bulk.BulkRequest> bulkRequestFn)
BulkRequest()
For example, to modify the BulkRequest used to index documents:
builder.bulkRequestFn(() -> new BulkRequest().setRefreshPolicy(IMMEDIATE))
bulkRequestFn
- supplier function for the bulk request@Nonnull public <T_NEW> ElasticSinkBuilder<T_NEW> mapToRequestFn(@Nonnull FunctionEx<? super T_NEW,? extends org.elasticsearch.action.DocWriteRequest<?>> mapToRequestFn)
For example, to create an IndexRequest for a versioned document:
builder.mapToRequestFn((mapItem) ->
new IndexRequest("my-index")
.source(map)
.version((Long) map.get("version"))
This parameter is required.T_NEW
- type of the items from the pipelinemapToRequestFn
- maps an item from the stream to an
IndexRequest
,
UpdateRequest
or DeleteRequest
@Nonnull public ElasticSinkBuilder<T> retries(int retries)
retries
- number of retries, defaults to 5Copyright © 2021 Hazelcast, Inc.. All rights reserved.