io.kestra.plugin.elasticsearch.Search Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plugin-elasticsearch Show documentation
Show all versions of plugin-elasticsearch Show documentation
Connect Elasticsearch search and analytics engine to Kestra workflows.
The newest version!
package io.kestra.plugin.elasticsearch;
import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.executions.metrics.Counter;
import io.kestra.core.models.executions.metrics.Timer;
import io.kestra.core.models.tasks.RunnableTask;
import io.kestra.core.models.tasks.common.FetchType;
import io.kestra.core.runners.RunContext;
import io.kestra.core.serializers.FileSerde;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.tuple.Pair;
import org.opensearch.client.opensearch.OpenSearchClient;
import org.opensearch.client.opensearch.core.SearchRequest;
import org.opensearch.client.opensearch.core.SearchResponse;
import org.opensearch.client.transport.rest_client.RestClientTransport;
import org.slf4j.Logger;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.io.*;
import java.net.URI;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static io.kestra.core.utils.Rethrow.throwConsumer;
@SuperBuilder
@ToString
@EqualsAndHashCode
@Getter
@NoArgsConstructor
@Schema(
title = "Send a search request.",
description = "Get all documents from a search request and store it as outputs."
)
@Plugin(
examples = {
@Example(
full = true,
code = """
id: elasticsearch_search
namespace: company.team
tasks:
- id: search
type: io.kestra.plugin.elasticsearch.Search
connection:
hosts:
- "http://localhost:9200"
indexes:
- "my_index"
request:
query:
term:
name:
value: 'john'
"""
)
}
)
public class Search extends AbstractSearch implements RunnableTask {
@Schema(
title = "The way you want to store the data.",
description = "FETCH_ONE output the first row, "
+ "FETCH output all the rows, "
+ "STORE store all rows in a file, "
+ "NONE do nothing."
)
@Builder.Default
@PluginProperty
private FetchType fetchType = FetchType.FETCH;
@Override
public Search.Output run(RunContext runContext) throws Exception {
Logger logger = runContext.logger();
try (RestClientTransport transport = this.connection.client(runContext)) {
OpenSearchClient client = new OpenSearchClient(transport);
// build request
SearchRequest.Builder request = this.request(runContext, transport);
logger.debug("Starting query: {}", request);
SearchResponse