Programmable Push Filters
You can use push-down filters in Redpanda Cloud to search through large Kafka topics that may contain millions of records. Filters are JavaScript functions executed on the backend, evaluating each record individually. Your function must return a boolean:
-
true
: record is included in the frontend results. -
false
: record is skipped.
Multiple filters combine logically with AND
conditions.
Add a JavaScript filter
To add a JavaScript filter:
-
Navigate to the topic’s Messages page.
-
Click Add filter > JavaScript Filter.
-
Define your JavaScript filtering logic in the provided input area.
Resource usage and performance
JavaScript filters are executed on the backend, consuming CPU and network resources. The performance of your filter depends on the complexity of your JavaScript code and the volume of data being processed. Complex JavaScript logic or large data volumes may increase CPU load and network usage.
Available JavaScript properties
Redpanda Cloud injects these properties into your JavaScript context:
Property | Description | Type |
---|---|---|
|
Record headers as key-value pairs (ArrayBuffers) |
Object |
|
Decoded record key |
String |
|
Schema Registry ID for key (if present) |
Number |
|
Partition ID of the record |
Number |
|
Record offset within partition |
Number |
|
Timestamp as JavaScript Date object |
Date |
|
Decoded record value |
Object/String |
|
Schema Registry ID for value (if present) |
Number |
Values, keys, and headers are deserialized before being injected into your script. |
JavaScript filter examples
Filter by header value
Scenario: Records tagged with headers specifying customer plan type.
headers: {
"plan_type": "premium"
}
let headerValue = headers["plan_type"];
if (headerValue) {
let stringValue = String.fromCharCode(...new Uint8Array(headerValue));
return stringValue === "premium";
}
return false;
Scenario: Records include a header with JSON-encoded customer metadata.
headers: {
"customer": "{"orgID":"123-abc","name":"ACME Inc."}"
}
let headerValue = headers["customer"];
if (headerValue) {
let stringValue = String.fromCharCode(headerValue);
let valueObj = JSON.parse(stringValue);
return valueObj["orgID"] === "123-abc";
}
return false;
Filter by timestamp
Scenario: Retrieve records from a promotional event.
return timestamp.getMonth() === 10 && timestamp.getDate() === 24;
Filter by schema ID
Scenario: Filter customer activity records based on Avro schema version.
return valueSchemaID === 204;
Filter JSON record values
Scenario: Filter transactions by customer ID.
{
"transaction_id": "abc123",
"customer_id": "cust789",
"amount": 59.99
}
return value.customer_id === "cust789";
Scenario: Filter orders by item availability.
{
"order_id": "ord456",
"inventory": {
"item_id": "itm001",
"status": "in_stock"
}
}
return value.inventory.status === "in_stock";
Scenario: Filter products missing price information.
return !value.hasOwnProperty("price");