Skip to main content

Filter Records

The Filter API enables you to retrieve records from your database that match specific filtering criteria. Results are always returned in descending order by last seen time (most recent first).

POST /v1/databases/{id}/records/filter

Path Parameters

ParameterTypeRequiredDescription
idstringYesThe ID of your Lightfeed database

Request Body

{
"filter": {
"condition": "AND", // Optional, defaults to "AND" if not specified
"rules": [
{
"column": "industry",
"operator": "equals",
"value": "Finance"
},
{
"condition": "OR",
"rules": [
{
"column": "employees",
"operator": "greater_than",
"value": 100
},
{
"column": "funding_amount",
"operator": "greater_than",
"value": 1000000
}
]
}
]
},
"time_range": {
"start_time": "2024-01-01T00:00:00Z",
"end_time": "2024-12-31T23:59:59Z"
},
"pagination": {
"limit": 100,
"cursor": "2024-07-01T00:00:00Z_1234"
}
}

Example Requests

Basic Filter

This example shows how to filter finance companies with more than 100 employees.

curl -X POST "https://api.lightfeed.ai/v1/databases/your-database-id/records/filter" \
-H "x-api-key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"filter": {
"rules": [
{
"column": "industry",
"operator": "equals",
"value": "Finance"
},
{
"column": "employees",
"operator": "greater_than",
"value": 100
}
]
},
"pagination": {
"limit": 100
}
}'

Complex Filter with Time Range

This example shows how to filter records with more complex conditions including a time range.

curl -X POST "https://api.lightfeed.ai/v1/databases/your-database-id/records/filter" \
-H "x-api-key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"filter": {
"condition": "AND",
"rules": [
{
"column": "industry",
"operator": "equals",
"value": "Finance"
},
{
"condition": "OR",
"rules": [
{
"column": "employees",
"operator": "greater_than",
"value": 100
},
{
"column": "funding_amount",
"operator": "greater_than",
"value": 1000000
}
]
}
]
},
"time_range": {
"start_time": "2024-01-01T00:00:00Z",
"end_time": "2024-12-31T23:59:59Z"
},
"pagination": {
"limit": 100
}
}'

Request Parameters

Filter Object (Required)

Defines filtering conditions to apply to the records. Filter uses a logical group structure:

"filter": {
"condition": "AND", // Optional, defaults to "AND" if not specified
"rules": [
// Array of field comparisons or nested logical groups
]
}

Field Comparison Rule

ParameterTypeRequiredDescription
columnstringYesDatabase column name to filter on
operatorstringYesComparison operator to use
valueanyYes*Value to compare against

*Not required for is_empty and is_not_empty operators.

Available Operators:

OperatorDescriptionExample Value Type
equalsExact matchString, Number, Boolean
not_equalsNot an exact matchString, Number, Boolean
greater_thanGreater than valueNumber
less_thanLess than valueNumber
greater_than_or_equalsGreater than or equal to valueNumber
less_than_or_equalsLess than or equal to valueNumber
containsString contains substringString
not_containsString does not contain substringString
starts_withString starts with substringString
ends_withString ends with substringString
is_emptyField is empty or nullNo value needed
is_not_emptyField is not empty or nullNo value needed

Logical Group Rule

ParameterTypeRequiredDescription
conditionstringNoLogical operator to apply: "AND" or "OR". Defaults to "AND"
rulesarrayYesArray of field comparisons or nested logical groups

Time Range (Optional)

Filter results based on the last seen time of records. If not specified, all records are included regardless of timestamp.

"time_range": {
"start_time": "2024-01-01T00:00:00Z",
"end_time": "2024-12-31T23:59:59Z"
}
ParameterTypeRequiredDescription
start_timestringNoISO 8601 timestamp for the start of the range
end_timestringNoISO 8601 timestamp for the end of the range

Pagination (Optional)

Control the number of results returned and navigate through large result sets.

"pagination": {
"limit": 100,
"cursor": "2024-07-01T00:00:00Z_1234"
}
ParameterTypeRequiredDescription
limitnumberNoMaximum number of results to return (default: 50, max: 100)
cursorstringNoCursor for pagination (from previous response)

Example Response

{
"results": [
{
"id": "1345",
"data": {
"company_name": "Acme Inc.",
"industry": "Finance",
"website": "https://acme.com",
"employees": 250,
"funding_amount": 5000000,
"is_public": false
},
"timestamps": {
"first_seen_time": "2022-03-15T14:22:13Z",
"last_changed_time": "2024-07-02T09:45:30Z",
"last_seen_time": "2024-10-01T18:30:45Z"
}
}
// Additional results...
],
"pagination": {
"limit": 100,
"next_cursor": "2024-07-01T00:00:00Z_1234",
"has_more": true
}
}

Response Structure

The response contains a list of records matching your filter criteria, sorted by last seen time (most recent first).

FieldTypeDescription
resultsarrayList of matching records
paginationobjectInformation for continued querying

Pagination Object

FieldTypeDescription
limitnumberThe requested limit parameter value from the original request
next_cursorstringToken to use for fetching the next page
has_morebooleanIndicates whether more results are available

Record Object

Each record in the results array has the following structure:

FieldTypeDescription
idstringUnique identifier for the record
dataobjectThe record's structured data
timestampsobjectTiming information for the record

Tips and Best Practices

Effective Filtering

  • Start with broad filters and progressively add constraints to narrow down results
  • Use nested conditions to create complex filtering logic
  • When filtering on text fields, consider using contains instead of equals for more flexible matching

Filter Examples

Simple single condition filter:

"filter": {
"rules": [
{
"column": "industry",
"operator": "equals",
"value": "Finance"
}
]
}

Multiple conditions with AND logic (default):

"filter": {
"rules": [
{
"column": "industry",
"operator": "equals",
"value": "Finance"
},
{
"column": "employees",
"operator": "greater_than",
"value": 100
}
]
}

Multiple conditions with OR logic:

"filter": {
"condition": "OR",
"rules": [
{
"column": "industry",
"operator": "equals",
"value": "Finance"
},
{
"column": "industry",
"operator": "equals",
"value": "Technology"
}
]
}

Optimizing for Performance

  • Be specific with your filters to reduce the result set
  • Use time ranges to limit the data being searched
  • Combine multiple condition types effectively