0
0
Elasticsearchquery~10 mins

Enrich processor in Elasticsearch - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Enrich processor
Start ingest pipeline
Receive document
Extract key field
Lookup enrich index with key
Match found?
NoSkip enrich
Yes
Merge enrich data into document
Pass enriched document to next processor
End ingest pipeline
The enrich processor takes a field from the incoming document, looks it up in an enrich index, and merges matching data into the document before continuing.
Execution Sample
Elasticsearch
PUT _ingest/pipeline/enrich-pipeline
{
  "processors": [
    {
      "enrich": {
        "policy_name": "user-policy",
        "field": "user_id",
        "target_field": "user_info"
      }
    }
  ]
}
Defines an ingest pipeline that enriches documents by looking up user info based on user_id and adds it under user_info field.
Execution Table
StepActionInput DocumentLookup KeyEnrich Index ResultOutput Document
1Receive document{"user_id": "123", "event": "login"}123-{"user_id": "123", "event": "login"}
2Lookup enrich index-123{"name": "Alice", "role": "admin"}-
3Merge enrich data---{"user_id": "123", "event": "login", "user_info": {"name": "Alice", "role": "admin"}}
4Pass to next processor---{"user_id": "123", "event": "login", "user_info": {"name": "Alice", "role": "admin"}}
5End pipeline---Pipeline finished with enriched document
💡 Pipeline ends after enriching document or skipping if no match found.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
document{"user_id": "123", "event": "login"}{"user_id": "123", "event": "login"}{"user_id": "123", "event": "login"}{"user_id": "123", "event": "login", "user_info": {"name": "Alice", "role": "admin"}}{"user_id": "123", "event": "login", "user_info": {"name": "Alice", "role": "admin"}}
lookup_key-123123123123
enrich_result--{"name": "Alice", "role": "admin"}{"name": "Alice", "role": "admin"}{"name": "Alice", "role": "admin"}
Key Moments - 3 Insights
What happens if the enrich index has no matching entry for the lookup key?
If no match is found (see execution_table step 2), the enrich processor skips merging and passes the original document unchanged to the next processor.
How does the enrich processor know which field to use for lookup?
The processor uses the 'field' parameter from the pipeline definition (shown in execution_sample) to extract the lookup key from the incoming document.
Where does the enriched data get added in the document?
The enriched data is merged under the 'target_field' specified in the pipeline (here 'user_info'), as shown in execution_table step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of 'lookup_key' after Step 1?
A123
B-
CAlice
D{"name": "Alice", "role": "admin"}
💡 Hint
Check variable_tracker column 'After Step 1' for 'lookup_key'
At which step does the document get enriched with user info?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look at execution_table 'Action' and 'Output Document' columns
If the enrich index had no matching entry, what would happen to the output document?
AThe pipeline would fail
BIt would be enriched with empty data
CIt would remain unchanged
DThe document would be deleted
💡 Hint
Refer to key_moments explanation about no match scenario
Concept Snapshot
Enrich processor syntax:
{
  "enrich": {
    "policy_name": "policy",
    "field": "lookup_field",
    "target_field": "field_to_add"
  }
}

Behavior: Looks up a value from an enrich index using 'field' from the document, merges found data under 'target_field'.
If no match, document passes unchanged.
Full Transcript
The enrich processor in Elasticsearch ingest pipelines takes a field from the incoming document, uses it as a key to look up data in an enrich index, and merges the found data into the document under a target field. The process starts by receiving the document, extracting the lookup key, querying the enrich index, and if a match is found, merging the data. If no match is found, the document continues unchanged. This allows adding extra information to documents during ingestion based on external data.