Skip to content

Commit d36c0a4

Browse files
authored
enhancement(elasticsearch sink): add pipeline config (#2734)
1 parent 6502b1f commit d36c0a4

4 files changed

Lines changed: 61 additions & 1 deletion

File tree

.meta/sinks/elasticsearch.toml.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ examples = [
188188
templateable = true
189189
description = "Index name to write events to."
190190

191+
[sinks.elasticsearch.options.pipeline]
192+
type = "string"
193+
common = true
194+
examples = ["pipeline-name"]
195+
description = "Name of the pipeline to apply."
196+
191197
[sinks.elasticsearch.options.query]
192198
type = "table"
193199
description = "Custom parameters to Elasticsearch query string."

config/vector.spec.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4741,6 +4741,13 @@ require('custom_module')
47414741
# * type: [string]
47424742
inputs = ["my-source-or-transform-id"]
47434743

4744+
# Name of the pipeline to apply.
4745+
#
4746+
# * optional
4747+
# * no default
4748+
# * type: string
4749+
pipeline = "pipeline-name"
4750+
47444751
# The component type. This is a required field that tells Vector which
47454752
# component to use. The value _must_ be `#{name}`.
47464753
#

src/sinks/elasticsearch.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub struct ElasticSearchConfig {
4141
pub index: Option<String>,
4242
pub doc_type: Option<String>,
4343
pub id_key: Option<String>,
44+
pub pipeline: Option<String>,
45+
4446
#[serde(default)]
4547
pub compression: Compression,
4648
#[serde(
@@ -353,6 +355,10 @@ impl ElasticSearchCommon {
353355
let mut query_params = config.query.clone().unwrap_or_default();
354356
query_params.insert("timeout".into(), format!("{}s", request.timeout.as_secs()));
355357

358+
if let Some(pipeline) = &config.pipeline {
359+
query_params.insert("pipeline".into(), pipeline.into());
360+
}
361+
356362
let mut query = url::form_urlencoded::Serializer::new(String::new());
357363
for (p, v) in &query_params {
358364
query.append_pair(&p[..], &v[..]);
@@ -523,6 +529,22 @@ mod integration_tests {
523529
use std::fs::File;
524530
use std::io::Read;
525531

532+
#[test]
533+
fn ensure_pipeline_in_params() {
534+
let index = gen_index();
535+
let pipeline = String::from("test-pipeline");
536+
537+
let config = ElasticSearchConfig {
538+
host: "http://localhost:9200".into(),
539+
index: Some(index.clone()),
540+
pipeline: Some(pipeline.clone()),
541+
..config()
542+
};
543+
let common = ElasticSearchCommon::parse_config(&config).expect("Config error");
544+
545+
assert_eq!(common.query_params["pipeline"], pipeline);
546+
}
547+
526548
#[test]
527549
fn structures_events_correctly() {
528550
let mut rt = runtime();

website/docs/reference/sinks/elasticsearch.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified_on: "2020-06-02"
2+
last_modified_on: "2020-06-03"
33
delivery_guarantee: "at_least_once"
44
component_title: "Elasticsearch"
55
description: "The Vector `elasticsearch` sink batches `log` events to Elasticsearch via the `_bulk` API endpoint."
@@ -58,6 +58,7 @@ endpoint][urls.elasticsearch_bulk].
5858
healthcheck = true # optional, default
5959
host = "http://10.24.32.122:9000" # optional, no default
6060
index = "vector-%F" # optional, default
61+
pipeline = "pipeline-name" # optional, no default
6162
```
6263

6364
</TabItem>
@@ -74,6 +75,7 @@ endpoint][urls.elasticsearch_bulk].
7475
host = "http://10.24.32.122:9000" # optional, no default
7576
id_key = "id" # optional, no default
7677
index = "vector-%F" # optional, default
78+
pipeline = "pipeline-name" # optional, no default
7779

7880
# Auth
7981
auth.password = "${ELASTICSEARCH_PASSWORD}" # required, required when strategy = "basic"
@@ -747,6 +749,29 @@ Index name to write events to.
747749
See [Document Conflicts](#document-conflicts) and [Template Syntax](#template-syntax) for more info.
748750

749751

752+
</Field>
753+
<Field
754+
common={true}
755+
defaultValue={null}
756+
enumValues={null}
757+
examples={["pipeline-name"]}
758+
groups={[]}
759+
name={"pipeline"}
760+
path={null}
761+
relevantWhen={null}
762+
required={false}
763+
templateable={false}
764+
type={"string"}
765+
unit={null}
766+
warnings={[]}
767+
>
768+
769+
### pipeline
770+
771+
Name of the pipeline to apply.
772+
773+
774+
750775
</Field>
751776
<Field
752777
common={false}

0 commit comments

Comments
 (0)