Snowflake, BigQuery & Databricks · Google BigQuery

BigQuery search indexes and accelerating log analytics

gcpHardbigquerysearch-indexlog-analyticsjson-optimization

Interview question

When should you build BigQuery Search Indexes, and how do they accelerate point lookups on log data?

How to answer

The short answer

Analyzing high-volume semi-structured machine logs, audit trails, and clickstream events in BigQuery often presents a cost and latency challenge. Engineers frequently need to locate a single error code, IP address, or user identifier buried inside billions of rows of unstructured text or nested payloads.

Without indexing, BigQuery must perform a full columnar scan of every petabyte of text data, consuming substantial slot capacity and scan budget.

How search indexes operate

BigQuery Search Indexes create an inverted index over specified text or JSON columns. The index maps individual alphanumeric terms, tokens, and symbols directly to the physical storage blocks where those values reside.

SQL
-- Build an inverted search index across all JSON log payloads
CREATE SEARCH INDEX idx_audit_payload
ON `my_project.telemetry.security_logs`(log_payload);

Once built, BigQuery automatically updates the search index asynchronously as new streaming data arrives into the table.

Querying with the SEARCH() function

To take advantage of the search index, use the native SEARCH() function in query filters:

SQL
-- Accelerated point lookup using inverted index
SELECT timestamp, server_id, log_payload
FROM `my_project.telemetry.security_logs`
WHERE SEARCH(log_payload, '`ERROR_AUTH_TOKEN_EXPIRED`');

When BigQuery detects the SEARCH() function matching an indexed column, the consults the inverted index. It scans only the specific Colossus storage blocks containing that exact token, skipping 99% of table storage. Point lookup queries that previously took 45 seconds finish in under 2 seconds.

Cost and maintenance considerations

Search indexes require balancing query savings against indexing compute and storage costs. Google charges storage fees for index data and compute fees for index creation and incremental updates (check current pricing).

Search indexes deliver maximum value on large tables exceeding 10 gigabytes where queries filter frequently on low-cardinality search tokens across semi-structured JSON text.