All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hazelcast.jet.elastic.ElasticSinks Maven / Gradle / Ivy

The newest version!
/*
 * 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> sink = ElasticSinks.elastic(
     *   map -> new IndexRequest("my-index").source(map)
     * );}
* * @param mapToRequestFn function that maps an item from a pipeline * to an indexing request */ @Nonnull public static Sink elastic( @Nonnull FunctionEx> mapToRequestFn ) { return elastic(ElasticClients::client, mapToRequestFn); } /** * Creates an Elasticsearch sink, uses a client obtained from * clientFn and maps items using given mapToRequestFn *

* Usage: *

Sink> sink = ElasticSinks.elastic(
     *   () -> ElasticClients.client("es-host", 9200),
     *   map -> new IndexRequest("my-index").source(map)
     * );
* * @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> mapToRequestFn ) { // Avoid ElasticSinkBuilder 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 - 2024 Weber Informatics LLC | Privacy Policy