(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to aggregate events by geohash in Real-Time Analytics: step by step

João Barros 25 de November de 2026 4 min read

Aggregating events by geohash in Real-Time Analytics lets you summarize geospatial data in real time — useful for heatmaps, detecting regional patterns and routing local alerts. This tutorial shows how to generate geohash, aggregate by precision level and maintain windowed metrics.

Prerequisites

  • Account with access to a Real-Time Analytics environment that accepts KQL (for example Azure Data Explorer/ADx or a service with KQL compatibility).
  • Event stream with fields latitude, longitude, event_time and event_type.
  • Basic knowledge of KQL and windowing concepts (tumbling/sliding).

Step 1: Choose the geohash precision

Geohash translates coordinates into strings that represent areas. The greater the number of characters, the smaller the area. Choose the level of detail according to the scale of your use case (e.g., 5-6 characters for city/region, 7-8 for neighborhoods/streets).

Step 2: Generate geohash from latitude/longitude

If your environment does not have a native geohash function, implement a simple function. In KQL you can use a plugin or run the function at ingestion. Simple example of a function in KQL pseudocode to illustrate the logic (replace with native implementation or extension when available):

// Função de exemplo (pseudocódigo) para obter prefixo geohash
define inline GetGeoHash(lat: real, lon: real, precision:int)
{
  // Implementação real tipicamente em extensão; aqui ilustrativo
  // Retorna string com 'precision' caracteres
  // Usa abordagem binária para lat/lon e mapeia para base32
  strcat("gh_", tostring(round(lat, 4)), "_", tostring(round(lon,4)))[0..precision-1]
}

Note: replace this function with a real library when moving to production. Many systems allow UDFs in Python/JS to compute geohash during ingestion.

Step 3: Normalize events and compute geohash at ingestion

Converting and annotating each event with geohash during ingestion makes aggregations much faster. If ingestion-time computation is not possible, do this in a staging table with a periodic query.

// Exemplo KQL para criar tabela staging com geohash calculado
staging_events
| extend event_time = todatetime(event_time), latitude = todouble(latitude), longitude = todouble(longitude)
| extend geohash = GetGeoHash(latitude, longitude, 6)
| project event_time, event_type, geohash
| into table events_with_geohash

Step 4: Aggregate by geohash with tumbling window

Use tumbling windows to summarize counts by geohash at regular intervals (e.g., 1 minute). This facilitates map visualization and detection of local spikes.

// Agregação por geohash a cada 1 minuto
events_with_geohash
| where event_time > ago(15m)
| summarize count_events = count() by bin(event_time, 1m), geohash
| order by event_time desc

Step 5: Aggregate additional metrics and local percentiles

Besides counts, aggregate metrics like average duration, value percentiles or error rate by geohash. For percentiles use functions like percentile() if available.

// Exemplo com média e 95.º percentil (se existir campo value)
events_with_geohash
| where event_time > ago(30m) and isnotnull(value)
| summarize count_events = count(), avg_value = avg(value), p95 = percentile(value,95) by bin(event_time, 5m), geohash

Step 6: Reduce noise with filtering and thresholds

Sporadic events can create noisy heatmaps. Apply filters to keep only geohashes with counts above a threshold or use temporal smoothing (moving average) per geohash.

// Filtrar geohash com pelo menos 10 eventos na janela
... | where count_events >= 10

// Exemplo de smoothing simples: média móvel por geohash (KQL make-series ou windowing)
events_with_geohash
| where event_time > ago(1h)
| make-series cnt = count() default=0 on event_time step 1m by geohash
| extend smooth = moving_average(cnt, 5)

Verify the result

Confirm you have geohash, event_time and aggregated metric columns. Check a few points: 1) counts by geohash make geographical sense; 2) increasing/decreasing precision changes granularity; 3) smoothing reduces visual fluctuations. Test with a known event set and validate geohash manually for some coordinates.

Conclusion

By aggregating events by geohash in Real-Time Analytics you get regional real-time views, useful for dashboards and local alerts. Next steps: integrate with visualization (maps), optimize geohash calculation at ingestion using UDFs and experiment with different precisions. Tip: start with 5-6 characters and adjust according to noise — which level of detail is most useful for your case?