The enrich processor helps add extra information to your documents automatically. It looks up data from another source and adds it to your data.
Enrich processor in Elasticsearch
{
"enrich": {
"policy_name": "policy_name_here",
"field": "field_to_match",
"target_field": "field_to_add_data",
"max_matches": 1
}
}policy_name is the name of the enrich policy you created.
field is the field in your document to match with the enrich index.
{
"enrich": {
"policy_name": "user_policy",
"field": "user_id",
"target_field": "user_details"
}
}{
"enrich": {
"policy_name": "product_policy",
"field": "product_code",
"target_field": "product_info",
"max_matches": 1
}
}This example creates an enrich policy to add user name and email from the users index. Then it simulates adding this info to a document with user_id 123.
PUT /users/_doc/1 { "user_id": "123", "name": "John Doe", "email": "john@example.com" } PUT /_enrich/policy/user_policy { "match": { "indices": ["users"], "match_field": "user_id", "enrich_fields": ["name", "email"] } } POST /_enrich/policy/user_policy/_execute POST /_ingest/pipeline/_simulate { "pipeline": { "processors": [ { "enrich": { "policy_name": "user_policy", "field": "user_id", "target_field": "user_info" } } ] }, "docs": [ { "_source": { "user_id": "123" } } ] }
You must create and execute the enrich policy before using the enrich processor.
The enrich processor works during ingest, so it adds data as documents are indexed.
Use max_matches to control how many matches to add; default is 1.
The enrich processor adds extra data to documents by matching fields.
It uses enrich policies created from other data sources.
This helps keep your data enriched without changing original sources.
Practice
enrich processor in Elasticsearch?Solution
Step 1: Understand the enrich processor role
The enrich processor is designed to add additional data to documents by matching fields from an external data source called an enrich policy.Step 2: Compare options with enrich processor function
Full-text search, document deletion, and automatic index creation describe other Elasticsearch features, not enrich processor functionality.Final Answer:
To add extra data to documents by matching fields from an enrich policy -> Option CQuick Check:
Enrich processor = add matched data [OK]
- Confusing enrich processor with delete or search operations
- Thinking enrich processor creates indexes
- Assuming it modifies original data sources
Solution
Step 1: Recall enrich processor syntax
The enrich processor requires the keys:policy_name,field, andtarget_fieldto specify the enrich policy, the field to match, and where to store enriched data.Step 2: Identify correct option
"enrich": {"policy_name": "my_policy", "field": "user_id", "target_field": "user_info"}correctly usespolicy_name,field, andtarget_fieldwith proper JSON quoting. Unquoted keys likepolicy_namecause syntax errors. Usingindexormatch_fieldare incorrect keys.Final Answer:
"enrich": {"policy_name": "my_policy", "field": "user_id", "target_field": "user_info"} -> Option BQuick Check:
Correct keys = policy_name, field, target_field [OK]
- Using wrong keys like 'index' or 'match_field'
- Omitting target_field key
- Incorrect JSON syntax or missing quotes
{
"enrich": {
"policy_name": "user_policy",
"field": "user_id",
"target_field": "user_data"
}
}If a document
{"user_id": "123"} matches the enrich policy with {"user_id": "123", "name": "Alice"}, what will be the resulting document after enrichment?Solution
Step 1: Understand enrich processor output
The enrich processor adds matched data under thetarget_field. Here,user_datawill contain the matched document from the enrich policy.Step 2: Apply to given document
The original document hasuser_id: 123. The enrich policy matches and returns{"user_id": "123", "name": "Alice"}. This is added underuser_data.Final Answer:
{"user_id": "123", "user_data": {"user_id": "123", "name": "Alice"}} -> Option AQuick Check:
Enrich adds matched doc under target_field [OK]
- Replacing original fields instead of adding under target_field
- Adding only a single field value instead of full matched doc
- Not nesting matched data inside target_field
{
"enrich": {
"policy_name": "product_policy",
"field": "product_id"
}
}When running the pipeline, you get an error. What is the likely cause?
Solution
Step 1: Check required keys for enrich processor
The enrich processor requirespolicy_name,field, andtarget_field. The configuration is missingtarget_field.Step 2: Validate other options
Incorrectpolicy_namevalue might cause errors but is not guaranteed. Thefieldvalue should beproduct_nameis incorrect becausefieldshould match the field to join on. Enrich processor cannot be used in ingest pipelines is false; enrich processor is valid in ingest pipelines.Final Answer:
Missing target_field key in the enrich processor configuration -> Option AQuick Check:
target_field is required in enrich processor [OK]
- Forgetting target_field key
- Assuming enrich processor can't be in pipelines
- Changing field name incorrectly
Solution
Step 1: Understand enrich processor filtering capabilities
The enrich processor itself does not support filtering conditions inside its config. Filtering must be done before or by the enrich policy data.Step 2: Choose correct approach for conditional enrichment
Creating an enrich policy that only contains active users ensures only active user data is matched and added. Adding amatchcondition orconditionkey inside the enrich processor is unsupported syntax. Using ascriptprocessor after does not prevent enrichment for inactive users.Final Answer:
Create an enrich policy that only indexes active users and use enrich processor normally -> Option DQuick Check:
Filter data in enrich policy, not in processor [OK]
- Trying to filter inside enrich processor config
- Using unsupported condition keys
- Filtering after enrichment instead of before
Ready to prove it?
Pass the test and this pattern moves unknown
