com.hazelcast.jet.elastic.ElasticSinks Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hazelcast-jet-elasticsearch-7 Show documentation
Show all versions of hazelcast-jet-elasticsearch-7 Show documentation
Elasticsearch 7 support for Hazelcast Jet
/*
* Copyright 2023 Hazelcast Inc.
*
* Licensed under the Hazelcast Community License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://hazelcast.com/hazelcast-community-license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.jet.elastic;
import com.hazelcast.function.FunctionEx;
import com.hazelcast.function.SupplierEx;
import com.hazelcast.jet.pipeline.Sink;
import org.elasticsearch.action.DocWriteRequest;
import org.elasticsearch.client.RestClientBuilder;
import javax.annotation.Nonnull;
/**
* Provides factory methods for Elasticsearch sinks.
* Alternatively you can use {@link ElasticSinkBuilder}
*
* @since Jet 4.2
*/
public final class ElasticSinks {
private ElasticSinks() {
}
/**
* Creates an Elasticsearch sink, uses a local instance of Elasticsearch
*
* Usage:
*
{@code Sink
*
* @param mapToRequestFn function that maps an item from a pipeline
* to an indexing request
*/
@Nonnull
public static Sink elastic(
@Nonnull FunctionEx super T, ? extends DocWriteRequest>> mapToRequestFn
) {
return elastic(ElasticClients::client, mapToRequestFn);
}
/**
* Creates an Elasticsearch sink, uses a client obtained from
* clientFn and maps items using given mapToRequestFn
*
* Usage:
*
Sink
*
* @param clientFn supplier function returning configured RestClientBuilder
* @param mapToRequestFn function that maps an item from a pipeline to an indexing request
* @param type of incoming items
*/
@Nonnull
public static Sink elastic(
@Nonnull SupplierEx clientFn,
@Nonnull FunctionEx super T, ? extends DocWriteRequest>> mapToRequestFn
) {
// Avoid ElasticSinkBuilder super T> inferred from mapToRequestFn
ElasticSinkBuilder builder = new ElasticSinkBuilder<>()
.clientFn(clientFn)
.mapToRequestFn(mapToRequestFn);
return builder.build();
}
/**
* Returns new instance of {@link ElasticSinkBuilder}
*/
@Nonnull
public static ElasticSinkBuilder builder() {
return new ElasticSinkBuilder<>();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy