📖 Scenario: You work as a data engineer. You need to preprocess incoming log data before storing it in Elasticsearch. This preprocessing will add a timestamp and convert a field to lowercase.
🎯 Goal: Build an Elasticsearch ingest pipeline that adds a timestamp and converts the user field to lowercase. Then simulate sending a document through this pipeline and see the processed output.
📋 What You'll Learn
Create an ingest pipeline named log_pipeline with two processors: set and lowercase
The set processor must add a field ingest_timestamp with the current timestamp
The lowercase processor must convert the user field to lowercase
Simulate ingesting a document with user field set to JohnDoe through the pipeline
Print the resulting document after processing
💡 Why This Matters
🌍 Real World
Ingest pipelines help preprocess and enrich data before indexing in Elasticsearch, making search and analysis more effective.
💼 Career
Data engineers and Elasticsearch administrators use ingest pipelines to automate data transformations and improve data quality.
Progress0 / 4 steps
1
Create the ingest pipeline with a set processor
Create an ingest pipeline named log_pipeline with a set processor that adds a field called ingest_timestamp with the value {{_ingest.timestamp}}.
Elasticsearch
Hint
Use the PUT _ingest/pipeline/log_pipeline API to create the pipeline. The set processor adds a field with the current ingest timestamp.
2
Add a lowercase processor to the pipeline
Update the log_pipeline to add a lowercase processor that converts the user field to lowercase. Keep the existing set processor.
Elasticsearch
Hint
Add a second processor object with "lowercase" and specify the user field.
3
Simulate ingesting a document through the pipeline
Use the _ingest/pipeline/log_pipeline/_simulate API to send a document with "user": "JohnDoe" through the pipeline.
Elasticsearch
Hint
Use the _simulate API with a document containing the user field set to JohnDoe.
4
Print the processed document output
Print the output of the simulation showing the document after processing by the pipeline.
Elasticsearch
Hint
Look at the docs array in the response. The user field should be lowercase and ingest_timestamp should be present.
Practice
(1/5)
1. What is the main purpose of an ingest pipeline in Elasticsearch?
easy
A. To create visualizations from data
B. To query documents faster
C. To backup Elasticsearch data
D. To modify documents before they are indexed
Solution
Step 1: Understand ingest pipeline role
An ingest pipeline processes documents before they are stored in Elasticsearch.
Step 2: Compare options to pipeline purpose
Only To modify documents before they are indexed matches this role; others describe unrelated tasks.
Final Answer:
To modify documents before they are indexed -> Option D
Quick Check:
Ingest pipeline = modify before indexing [OK]
Hint: Ingest pipelines change data before saving [OK]
Common Mistakes:
Confusing pipelines with query optimization
Thinking pipelines create backups
Assuming pipelines generate reports
2. Which of the following is the correct way to define a processor that adds a field "source": "web" in an ingest pipeline?
easy
A. "processors": [{"add": {"field": "source", "value": "web"}}]
B. "processors": [{"remove": {"field": "source", "value": "web"}}]
C. "processors": [{"set": {"field": "source", "value": "web"}}]
D. "processors": [{"append": {"field": "source", "value": "web"}}]
Solution
Step 1: Identify processor to add or set field
The set processor assigns or adds a field with a value.
Step 2: Check syntax correctness
"processors": [{"set": {"field": "source", "value": "web"}}] uses set with correct JSON structure; add is not a valid processor name.
Final Answer:
"processors": [{"set": {"field": "source", "value": "web"}}] -> Option C
Quick Check:
Use set to add fields [OK]
Hint: Use 'set' processor to add or update fields [OK]