use faucet_stream::sink::elasticsearch::{
ElasticsearchAuth, ElasticsearchSink, ElasticsearchSinkConfig,
};
use faucet_stream::source::postgres::{PostgresSource, PostgresSourceConfig};
use faucet_stream::{Pipeline, json};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let source = PostgresSource::new(
PostgresSourceConfig::new(
"postgres://user:pass@localhost/app",
"SELECT id, title, body, tags FROM articles WHERE published = $1",
)
.params(vec![json!(true)])
.with_max_connections(8),
)
.await?;
let sink = ElasticsearchSink::new(
ElasticsearchSinkConfig::new("https://es.example.com:9200", "articles")
.auth(ElasticsearchAuth::ApiKey {
key: std::env::var("ES_API_KEY")?,
})
.with_batch_size(500)
.id_field("id"),
)?;
let result = Pipeline::new(&source, &sink).run().await?;
println!(
"indexed {} articles into Elasticsearch",
result.records_written
);
Ok(())
}