1. Transforms #
Pivot and latest.
Why #
Aggregations answer on the fly, but some questions are about entities: each customer's summary, each server's latest state. A transform computes that summary once, writes it to a destination index and keeps it up to date.
Pivot #
PUT _transform/web-par-hote
{
"source": { "index": "logs-nginx.access-*" },
"dest": { "index": "web-par-hote" },
"pivot": {
"group_by": {
"hote": { "terms": { "field": "host.name" } },
"heure": { "date_histogram": { "field": "@timestamp", "calendar_interval": "1h" } }
},
"aggregations": {
"requetes": { "value_count": { "field": "@timestamp" } },
"octets": { "sum": { "field": "http.response.body.bytes" } }
}
},
"sync": { "time": { "field": "@timestamp", "delay": "60s" } },
"frequency": "5m"
}
POST _transform/web-par-hote/_startLatest #
PUT _transform/dernier-etat-hote
{
"source": { "index": "metrics-system.cpu-*" },
"dest": { "index": "dernier-etat-hote" },
"latest": { "unique_key": ["host.name"], "sort": "@timestamp" },
"sync": { "time": { "field": "@timestamp" } }
}| Mode | Behaviour |
|---|---|
| batch | one-off computation on existing data |
| continuous | with sync: regular updates according to frequency |
Good practice: Test withPOST _transform/_previewbefore creating, and followGET _transform/<id>/_stats: processed documents, failures, lag.
2. Enriching at ingest #
Enrich policies.
Policy and processor #
PUT _enrich/policy/serveurs
{ "match": { "indices": "referentiel-serveurs", "match_field": "host.name", "enrich_fields": ["equipe", "environnement"] } }
POST _enrich/policy/serveurs/_execute
PUT _ingest/pipeline/logs-nginx.access@custom
{ "processors": [ { "enrich": { "policy_name": "serveurs", "field": "host.name", "target_field": "serveur" } } ] }Common mistake: Forgetting to re-execute the policy: the enrich index is a frozen copy of the reference data. After changing the reference data, run _execute again (for example nightly).| Type | Matching |
|---|---|
| match | exact value (ID, name) |
| range | range (IP address range) |
| geo_match | geographic shape |
3. Enriching at query time #
ES|QL
ENRICH and LOOKUP JOIN #
FROM logs-nginx.access-*
| ENRICH serveurs ON host.name WITH equipe
| STATS erreurs = COUNT(*) BY equipeDepending on the version:LOOKUP JOIN(join with a lookup-mode index) is available in recent versions (8.18 / 9.x);ENRICHrelies on the same enrich policies as ingest.
