Example: Enrich your data based on exact values
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Generally available
Stack
Generally available
match enrich policies match enrich data to incoming documents based on an exact value, such as a email address or ID, using a term query.
The following example creates a match enrich policy that adds user name and contact information to incoming documents based on an email address. It then adds the match enrich policy to a processor in an ingest pipeline.
Use the create index API or index API to create a source index.
The following index API request creates a source index and indexes a new document to that index.
PUT /users/_doc/1?refresh=wait_for{ "email": "mardy.brown@example.com", "first_name": "Mardy", "last_name": "Brown", "city": "New Orleans", "county": "Orleans", "state": "LA", "zip": 70116, "web": "mardy.example.com" }
Use the create enrich policy API to create an enrich policy with the match policy type. This policy must include:
- One or more source indices
- A
match_field, the field from the source indices used to match incoming documents - Enrich fields from the source indices you’d like to append to incoming documents
PUT /_enrich/policy/users-policy{ "match": { "indices": "users", "match_field": "email", "enrich_fields": ["first_name", "last_name", "city", "zip", "state"] } }
Use the execute enrich policy API to create an enrich index for the policy.
POST /_enrich/policy/users-policy/_execute
Use the create or update pipeline API to create an ingest pipeline. In the pipeline, add an enrich processor that includes:
- Your enrich policy.
- The
fieldof incoming documents used to match documents from the enrich index. - The
target_fieldused to store appended enrich data for incoming documents. This field contains thematch_fieldandenrich_fieldsspecified in your enrich policy.
PUT /_ingest/pipeline/user_lookup{ "processors" : [ { "enrich" : { "description": "Add 'user' data based on 'email'", "policy_name": "users-policy", "field" : "email", "target_field": "user", "max_matches": "1" } } ] }
Use the ingest pipeline to index a document. The incoming document should include the field specified in your enrich processor.
PUT /my-index-000001/_doc/my_id?pipeline=user_lookup{ "email": "mardy.brown@example.com" }
To verify the enrich processor matched and appended the appropriate field data, use the get API to view the indexed document.
GET /my-index-000001/_doc/my_id
The API returns the following response:
{
"found": true,
"_index": "my-index-000001",
"_id": "my_id",
"_version": 1,
"_seq_no": 55,
"_primary_term": 1,
"_source": {
"user": {
"email": "mardy.brown@example.com",
"first_name": "Mardy",
"last_name": "Brown",
"zip": 70116,
"city": "New Orleans",
"state": "LA"
},
"email": "mardy.brown@example.com"
}
}