RousselTMLEARNING

Observability

Transforms and enrich: summarising and enriching data in Elasticsearch

Build entity-centric indices with pivot and latest transforms, and enrich documents at ingest time with enrich policies, or at query time with ES|QL.

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.

Source index, transform, destination index, dashboards.

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/_start

Latest #

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" } }
}
ModeBehaviour
batchone-off computation on existing data
continuouswith sync: regular updates according to frequency
Good practice: Test with POST _transform/_preview before creating, and follow GET _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).
TypeMatching
matchexact value (ID, name)
rangerange (IP address range)
geo_matchgeographic 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 equipe
Depending on the version: LOOKUP JOIN (join with a lookup-mode index) is available in recent versions (8.18 / 9.x); ENRICH relies on the same enrich policies as ingest.

Related articles

OpenTelemetry and Elasticsearch: compatibility and architecture

Send OpenTelemetry to Elasticsearch: Collector and elasticsearch exporter, managed OTLP endpoint, APM Server,…

Ingesting OpenTelemetry logs into Elasticsearch

Collect and structure logs with the OpenTelemetry Collector (filelog receiver, operators, transform processor…

OpenTelemetry traces in Elasticsearch and Kibana APM

Instrument applications with OpenTelemetry or EDOT SDKs, send traces to Elasticsearch, get Kibana APM views, …

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!