When datastore_search fits an application back end
The datastore_search action serves filtered, searched and paginated rows from a DataStore table through the CKAN Data API, and from the application's side it is read-only. A team that has loaded a tabular resource into the DataStore and now needs a map, dashboard or service to ask for subsets of rows can call this action instead of fetching the whole table on every page view. The application reads through the DataStore's read-only database user, so it cannot change stored rows, and writes happen through the loading process, not through this read path. Before building anything, confirm that the resource is in the DataStore at all. A resource that exists only as an uploaded or linked file has no queryable table yet, so a request against its resource ID will not return rows. Run one test request against the resource ID to confirm that the field list comes back as expected.
Query the Data API directly when the consumer needs a small answer that changes with user input: one district's records, the results of a search box, or one page in a table widget. Each request then returns only the fields and rows it asks for, and the server does the filtering. Download the full table when the consumer needs every row at once, such as an analysis job, a bulk import or an offline copy. Paging through a large table with many requests adds load and failure points that a single file download avoids. The full-table route is covered in the DataStore downloads topic. Test each consumer against both paths before choosing, because a dashboard and a nightly processing job built on the same resource often need different routes, and the choice affects how much load the portal carries.
The filter syntax depends on your CKAN version. Exact matches, lists treated as OR, and the range operators lt, lte, gt and gte are available in datastore_search, while $or groups require CKAN 2.12 or later. Confirm your portal's version before writing front-end code that depends on $or, because a query that works on a test instance may fail on an older production portal. If the portal runs an earlier version, keep the application to exact matches and lists, or put the upgrade into the plan first. Get the exact parameter names and examples from the CKAN DataStore documentation before writing code, since that page defines how each operator behaves.
Filter and search options and when each one fits
This table compares the filter and search options in datastore_search and shows when each one fits an application back end. Read each row for its use case, the CKAN version it needs, and the main cost or trade-off to test before you ship. Check the exact behavior of q, full_text and plain against the DataStore documentation for your target version, since search cost grows with broad queries.
| Option | Use it when | CKAN version | Main trade-off |
|---|---|---|---|
| Exact match | One column must equal a known value, such as a status code or region name | Confirm for your version | Stored text must match exactly, so check how each column was loaded and its casing |
| Lists as OR | A column may hold any of several values, such as a set of category codes | Confirm for your version | Each added value widens the result, so large tables still need row limits and paging |
| Range operators (lt, lte, gt, gte) | Date or numeric windows, such as records from one reporting period | CKAN 2.12 or later | Ranges compare values by their stored type, so confirm column types first; wide windows scan more rows |
| $or groups | Matching on either of two conditions, such as a name or an identifier field | CKAN 2.12 or later | Nested or large groups are harder to test and can raise query cost, so keep them shallow |
| q (free-text search) | Users type keywords and expect matches across the text in a table | Confirm for your version | Broad terms match many rows and cost more to run, so pair q with filters and a row limit |
| full_text | Keyword search over text columns, after you confirm which columns it covers | Confirm for your version | Its matching rules can differ from q, so test both on your own data before choosing one |
| plain set to false | You need PostgreSQL query syntax, such as boolean and phrase operators, in the search term | Confirm for your version | Malformed syntax can fail, so validate user input and decide whether end users can send raw syntax |
| Field selection (fields) | An app displays only a few columns and should receive less data per row | Confirm for your version | Clients that later need more columns must change their request, so document the field list |
How datastore_search turns a request into a PostgreSQL query
Every datastore_search request becomes a SQL statement against the table that holds the resource's rows. That table lives in the DataStore's own PostgreSQL database, separate from the database that stores CKAN's catalog metadata. The Data API runs these statements through the read-only database user, so a filter or search term can read rows but cannot write them. That protection only holds if your application's reads actually reach the DataStore through that path, so confirm which connection URL and role your CKAN instance uses for read queries before you rely on it. The write user handles loading and writes, and it should not appear in the configuration your back end uses for searches.
The filters parameter maps exact matches to equality conditions on named columns, and a list value to an OR across its entries. The range operators lt, lte, gt and gte compare a column against a value, and $or groups add alternative conditions. These advanced filters require CKAN 2.12 or later, so check your version before you design around them. Free-text terms go in q, used together with the full_text parameter, and you should confirm the exact behavior of full_text for your version in the DataStore documentation. The plain setting decides whether the term is treated as plain text or as PostgreSQL query syntax, and setting it to false allows the query syntax. Send only the fields you need in fields, because every column you request is read and returned for each matching row, which costs time on wide tables and memory in your application.
The loader decides what PostgreSQL sees, and filtered queries are only as fast as the indexes and column types it produced. A column loaded as text compares as strings, so a range such as gt 9 on values like 10 and 9 can return unexpected results (illustrative). A filter on a column with no suitable index forces the database to scan the table for each request. Choose the loader with filtered back ends in mind, check the column types after the first load, and correct any wrong types through a reload before the application depends on them. Then run the exact filter, range and search combinations your application sends against a table of production size, and record the response times so the performance check can be repeated.
Every application query reads the DataStore through the read-only user
The application back end sends an HTTP request to the CKAN Data API, which passes it to the datastore_search action. That action applies the filter, the q full-text term and the fields selection, then runs the resulting query against the DataStore PostgreSQL database through the read-only user. The API tier is the trust boundary: requests are accepted on its side, and the database accepts only what that role can read. The write user loads tables and stays outside the query path. Results return as JSON with pagination. Confirm that the API connects with the read-only role, and that $or groups are used only on CKAN 2.12 or later.
Application requests reach the DataStore only through the read-only user.
Setting up datastore_search filters in your application
This sequence confirms the CKAN version, the DataStore table and the query parameters before your application depends on them. Each step runs against a staging resource, so filter problems surface before users see them.
Confirm the CKAN version supports advanced filters
The platform team checks the running CKAN version on the staging site before writing any query. The $or groups and the advanced range and list filters require CKAN 2.12 or later. CKAN 2.12.0 was released on August 26, 2026, so confirm that date and the details in the CKAN release notes before you pin the version. If the site runs an earlier minor version, plan the upgrade first. The step is done when the status_show action reports 2.12 or later on the staging site and staging matches the version planned for production.
Confirm the resource is loaded into DataStore
The platform team confirms that the resource has a DataStore table and that the loader job finished. Check the DataStore view on the resource page, then call datastore_search on the resource with a small limit. A healthy table returns rows, an _id column and a total that matches the row count in the source file. If the table is missing, the loader or its job worker needs attention before any filter work begins. The step is done when an unfiltered call returns the same total as the source file.
Match column names and types to the contract
The application team compares the column names and types in the table with the contract their code expects. Run datastore_search with limit set to 1 and review the fields list in the response, since column names are case-sensitive. Text columns compare lexically, so a range filter on a number stored as text can return the wrong rows. Decide now whether numeric and date columns need correcting before the application is built. The step is done when every field your queries use appears with the expected name and a type that supports the operators you plan to use.
Test exact filters against a known count
The application team runs exact-match filters one at a time on the staging resource. Pick two or three values you can count in the source file, send each through the filters parameter as a JSON object, and compare the total in the response with your count. Include one value that should return no rows. The filter syntax is described in the CKAN DataStore documentation. The step is done when every total matches your count and the returned rows contain only the filtered value in that column.
Test range, list and $or filters with boundary values
Test lt, lte, gt and gte on a numeric or date column, using a boundary value that exists in the data. Confirm that lte and gte include the boundary row while lt and gt exclude it. Then test a list value, which matches rows with any listed item, and an $or group that combines two conditions. Compare each total with a count from the source file or a trusted spreadsheet filter. The step is done when every boundary behaves as expected, each list total equals the sum of its single-value totals, and each $or total matches the union of its two branches.
Test full-text search with q and plain
Run a full-text search with the q parameter for a term you know appears in the data, then check that each returned row contains the term in a searchable field. Confirm whether your queries use q or full_text, and keep plain set to false if your application needs PostgreSQL query syntax. Compare the total with a count from the source file for the same term. The step is done when the total matches the expected count, the hits contain the term, and a query with PostgreSQL operators returns the results your team expects.
Select only the fields the application needs
Add the fields parameter to a query that returns the columns your interface displays. Confirm that the response contains only those columns and the metadata your client code expects, and that key names match the contract. Compare the total with the same filter run without field selection, because selecting fields should not change which rows match. The step is done when the returned columns match the list in your contract and the total is unchanged.
Handle pagination and errors in the client
The application team builds the client loop around limit and offset, reads the total on each page, and stops when the collected rows equal the total. Sort by _id so pages do not overlap, and confirm the page size against the limits on the staging site. For very large tables, plan keyset pagination on _id. Treat a response with success set to false as an error, log the message and the query, and show users a clear message instead of an empty result. The step is done when a test script collects every row of a filtered query without duplicates and a bad filter produces a logged error.
Security and operational considerations for search endpoints
Search endpoints sit between application traffic and your DataStore tables, so their security depends on database roles, visibility checks and how clients call the API. The cards below cover the controls to set before launch and the signals to watch once traffic arrives. Each one maps to a check you can run in your own environment.
Read-only database user
Search requests should run through the DataStore's read-only database user, which keeps query traffic from changing table contents. Confirm that the DataStore's search calls connect with that role and that the write user's credentials appear only in the configuration used for loading data. Check the role's grants again after any change to the DataStore database, and make sure no browser-side code, sample notebook or public repository contains either connection string. The role limits what a query can change, and load is a separate concern covered in the next card.
DataStore docsVisibility rules for private resources
Private datasets and their resources must return no rows to users who lack read access, and the search endpoint is where a gap is easiest to miss. Filters, ranges and full-text terms should apply after the visibility check, so a broad query never reveals row counts or matching values from a hidden resource. Test with three callers: anonymous, a signed-in user outside the owning organization, and a member of that organization. Compare returned rows and total counts for each caller, then repeat the test after changing collaborator roles or switching a dataset between private and public.
Free-text and broad OR queries
Full-text search with q and large $or groups can scan many rows, so a handful of clients repeating them can keep the database busy even when each response is small. Set a page size limit in your application, cap the number of values a user can send in one list or $or group, and build query forms that do not pass raw free text into the filter. Confirm which columns carry indexes before you publish filter options, and time your heaviest expected queries on the largest table you plan to expose. The $or groups require CKAN 2.12 or later, so confirm your version first.
API tokens for application clients
Application back ends should call the Data API with one API token per application, held in server-side configuration and sent in the request header. Keep tokens out of front-end JavaScript, public repositories and query strings, where they can end up in browser history, proxy logs and shared links. Give each application its own CKAN user with the lowest organization role that reads the datasets it needs, so a leaked token exposes only that scope. Rotate tokens when an application changes owner or when a team member who handled them leaves.
Logging query patterns for capacity
Log each datastore_search call with the resource ID, the filter fields used, whether q or $or appeared, the page size and the response time. These fields show which query patterns drive load, and that is the input capacity planning needs. Keep API tokens out of the log, and hash or drop user-entered search text, since it can contain personal data. Review the log regularly during early operation, then compare the heaviest resources and slowest patterns with your database sizing and caching decisions.
Re-test after each minor upgrade
CKAN minor releases may include backwards-incompatible changes, while patch releases are meant to keep compatibility, so each type calls for a different test depth. After each minor upgrade, rerun the visibility, read-only role and query timing tests against the new version, and confirm that the filter and full-text behavior your application relies on still holds. Run a shorter smoke test of the same endpoints after patch releases. Keep the test cases in version control so each run covers the same ground, and check the support window for your current minor version before scheduling the upgrade.
CKAN release policyChoosing a filter pattern for each kind of application
A map or dashboard usually asks for one window of time or one area per request, then draws many rows at once. Range filters fit this work because the front end sends a lower bound and an upper bound on a single column. The example below is illustrative: a dashboard that shows inspections between two dates for one district, using a hypothetical inspected_on column.
- Range filters on dates and numbers: Send
gteandlteon the date column so each panel asks for one window, and send an exact match for the district code in the same request. - CKAN version: Range operators need CKAN 2.12 or later. Confirm the release on your staging site before you design panels around them.
- Sorted results: Request a sort on the column you plot so the chart receives rows in a predictable order on every reload.
- Typed columns: Check that the loader stored dates and numbers with types the comparison expects. A column loaded as text may compare differently, so test a known boundary value.
- Map bounds: Latitude and longitude range filters can approximate a bounding box. Confirm with the mapping team that the approximation meets their needs before you build on it.
Before release, test the boundary dates, an empty window, and a window that covers the whole table, and compare each count with a direct count on a staging copy.
A lookup form takes an identifier that a user already knows or a term typed into a search box. Exact matches fit codes, reference numbers and dropdown values, while free text fits names and descriptions and runs through the q parameter. The example below is illustrative: a form that finds a licence by its reference code or by a word in the business name.
- Exact matches on identifiers: Pass the reference code in
filtersas an exact match so the form returns one row or none. - Free text with q: Send the typed term in
qto search text columns. Test how the search handles punctuation, accents and multiple words on your own data, because results depend on column types and the search index. - Plain syntax: Set
plainto false only when you need PostgreSQL query syntax inq. Keep user input on the plain path unless you have tested how malformed syntax fails. - Field selection: Use
fieldsto return only the columns the form displays, so responses stay small and internal columns stay out of the public response. - Version check: Confirm exact matches and
qbehavior on your release. If the form needs alternate keys, check whether the $or groups in CKAN 2.12 or later fit the design.
Before release, test empty input, a term with quotes and special characters, a code that does not exist, and a common word that matches many rows.
A partner integration needs a contract: the same fields, in the same order, with paging that does not shift between calls. The partner builds a client once and expects it to keep working after each site update. The example below is illustrative: a logistics partner that pulls a fixed set of six columns from a published transit table.
- Fixed field list: Name the columns in
fieldsand publish that list as the contract. Any column change then becomes a versioned change the partner can plan for. - Stable paging: Sort on
_idand filter on the last_idreturned, so pages do not skip or repeat rows when new rows arrive. Offset paging slows down and drifts on large tables. - Filter contract: List the filters partners may use. If a partner relies on range operators or $or groups, state in the contract that the site must run CKAN 2.12 or later.
- Upgrade testing: Minor CKAN releases may include backwards-incompatible changes, so replay partner queries on staging after each minor upgrade before production.
- Patch releases: Patch releases are not expected to break backwards compatibility, but replay the partner queries after them as well.
Before release, replay the full paged sequence on staging, compare row counts and key order with a saved snapshot, and confirm that a row added mid-sequence does not appear twice.
Category services accept a set of values and return rows that match any of them. This is OR logic, and it appears in two shapes: several values in one column, or matches spread across different columns. The example below is illustrative: a service that returns notices tagged with any of three hypothetical categories.
- Lists as OR on one column: Pass a list of values for one column in
filtersso rows match any listed value. Confirm the list behavior on your release before the service depends on it. - $or groups across columns: When a match can land in different columns, use an $or group. This needs CKAN 2.12 or later.
- Combining with other filters: Mixing an $or group with exact or range filters changes the meaning of the whole query. Write the expected logic in plain words first, then check that the query matches it.
- Result size: A broad category set can match most of the table. Set a limit, page through results, and time the query for the largest category.
- Empty and single values: Define how the service answers a request with no categories and a request with one category, since the service contract should cover both.
Before release, compare each category query with a direct count on a staging copy, and test an empty category, a single category, and a combination that returns no rows.
Limits to confirm in your CKAN environment
Each card covers an assumption that is easy to make and costly to fix later. Confirm these points against your target CKAN version and your loaded tables before the application's query design is final, and record the answers in your implementation notes.
Advanced filter support by version
The advanced filters, including $or groups and the range operators lt, lte, gt and gte, require CKAN 2.12 or later. An application that depends on them will fail on an older portal, so the target version sets the query design. Ask which CKAN version runs in production and whether staging matches it. Check the DataStore docs for the exact version you will deploy, since the feature list changes between releases.
CKAN DataStore docsRow limits and timeouts
Filtered results pass through the row limits and query timeouts configured on your CKAN instance. A filter that matches a large share of a table can return fewer rows than your application expects, or stop before it finishes. Ask the operations team for the configured maximum rows per request and the DataStore query timeout. Then test a broad filter against your largest table and confirm that pagination returns the rows you expect.
Full-text index per resource
The full-text search index is built for each loaded resource, so q and full_text only search tables that have been loaded and indexed on your instance. Confirm when the index is created, how it is refreshed after a reload, and how it is updated after row-level changes. A table loaded through a different path may be indexed differently. Run a search against a freshly reloaded table before any front end depends on it, and keep that check in your release runbook.
Plain query syntax behavior
Setting plain to false switches q to PostgreSQL query syntax, which changes how the search terms are parsed. Check the datastore_search behavior for plain query syntax in the docs for your exact CKAN version, because minor releases may include backwards-incompatible changes. Run a short set of test queries that includes quoted phrases and boolean operators. Record the results as a baseline so you can detect changes after each upgrade.
DataStore search docsColumn types from the loader
Range operators compare values according to the column type. A date or number stored as text sorts and compares differently from a numeric or date column, so a range filter can return unexpected rows. Find out which loader populated each resource and how it infers types. Then inspect column types before publishing range filters by running a sample query on each table. If a type is wrong, plan the override before you publish the filter contract, because a later reload can change the types again.
Quoting uppercase field names
Where a field name appears inside an SQL-style expression, PostgreSQL folds unquoted names to lowercase, so a column with uppercase letters must be quoted exactly as stored in the DataStore. Confirm which parts of your request your CKAN version passes into SQL, such as plain query syntax or sort clauses, and which parts are handled as plain JSON keys. Test one uppercase column in each path before the application goes live.
Questions teams ask before building on datastore_search
What does a search back end on datastore_search cost to build?
Cost follows from the written scope, and DeployOpen does not publish a price list, so the figure comes from a quote built on agreed inputs. The build splits into a few parts: the DataStore queries for the filters and full-text search your application needs, a thin back-end layer that maps application requests to those queries, testing against a staging resource, and documentation for your team. The main cost drivers are the number of resources and query patterns, how clean the column types are after loading, whether you need $or groups (which require CKAN 2.12 or later), and whether the application front end is included. Build work is one-time, while support, upgrades and continuous testing recur under a retainer. Ask for each part as a separate line in the quote, and state the CKAN version you run.
How long does a first working datastore_search integration take?
The duration is set by scope and inputs, so confirm the timeline against the written scope before work starts. Three factors drive the time to a first working integration: how cleanly the source file loaded into the DataStore, meaning column types and whether values need cleaning; how many filter and search combinations the application must support; and how quickly the team gets a staging resource and CKAN access. Loading problems add time because the query layer cannot be tested properly until the table is right. A narrow first release covering a few resources and a small set of filters usually reaches a working state sooner than a full catalog of queries, so agree that boundary in writing.
What does the client need to provide for a datastore_search build?
The work needs three inputs from your side, and each should be named in the written scope:
- Access to the CKAN portal, including an API token or an approved account that can read the target datasets and resources.
- A staging resource that matches the production table in structure, so filter and search behavior can be tested without touching published data.
- A named owner for column types, who confirms which fields are dates, numbers or text and signs off when a reload changes them.
Also name a contact on the application team and record the CKAN version and extensions in use. Missing any of these usually delays the start, so raise them during scoping.
Can our internal team build a datastore_search integration without a partner?
Yes, an internal team with CKAN experience, working knowledge of the application language and familiarity with PostgreSQL can build the integration alone. The questions to weigh are continuity and capacity: whether someone can own column types, loader behavior and upgrades after the first release, and whether the team has time to test filters, full-text search and pagination against realistic query patterns. An outside partner adds value when the timeline is fixed, when the team lacks CKAN depth, or when independent review of security settings is required. Compare your own effort with a written scope from a partner, and count ongoing upkeep as well as the first build.
What changes for datastore_search when we upgrade CKAN?
The main change is feature availability. The advanced filters, including $or groups, require CKAN 2.12 or later, so a portal on an earlier version needs the upgrade before those queries work. Patch releases do not break backwards compatibility and exclude schema changes and new features, while minor releases may include backwards-incompatible changes. Check the application's query code, the DataStore settings and every extension against the CKAN release policy and the release notes before upgrading. Test the upgrade on staging using the same datastore_search calls your application makes, and plan it as its own piece of work with a rollback path.
How do exact filters and full-text search differ in datastore_search?
Exact and range filters narrow rows by column value, while full-text search matches text across the table through the q parameter. Exact matches take one value per field, lists act as OR within a single field, and the range operators lt, lte, gt and gte handle numbers and dates. The advanced forms, including $or groups, need CKAN 2.12 or later. The full_text setting and the plain option control how the search text is interpreted, and setting plain to false passes it as PostgreSQL query syntax, so test both behaviors on your own data before exposing them. Field selection limits the columns returned, which keeps responses small. Confirm exact parameter behavior in the DataStore documentation for your CKAN version.
What should we check before exposing datastore_search to public users?
Confirm that the application reads the DataStore through the read-only database user, not the write user, and that the permissions set during setup still match. Check resource-level visibility, because private datasets and resources must stay hidden from anonymous callers. Set and test a row cap so one broad query cannot return an unbounded result, and agree the page size with the application team. Log requests and watch for slow queries against large tables. Decide which filters and fields are exposed, since each exposed column becomes part of the public contract. A security test can cover these checks before launch.
How DeployOpen scopes and delivers DataStore search work
DeployOpen plans and builds DataStore search for application back ends inside your own CKAN environment, starting from the queries your application needs to run. Filters, $or groups, full-text search and field selection are tested against your actual resource tables before they reach production. Engagements are fixed-scope, and the written scope fixes what is delivered.
How we scope
- The written scope lists the query patterns your application needs, such as exact filters, range filters and full-text search.
- We confirm your CKAN version first, since $or groups need CKAN 2.12 or later, and CKAN 2.12.0 was released on August 26, 2026.
- Ongoing support and continuous testing are available as a retainer for the search layer.
How we build
- Filters are written against the resource's column names and types, with lists treated as OR conditions.
- Range operators lt, lte, gt and gte are tested against boundary values on the columns they filter.
- Full-text search uses q and full_text, with plain set to false only where PostgreSQL query syntax is needed.
How we hand over
- The handover includes the search query catalog, with each filter, $or group and field selection documented.
- Test cases record expected row counts for each query, so regressions show up after CKAN upgrades.
- Your team receives the configuration, the read-only access setup the application uses, and a runbook for the search layer.
How we support
- Support covers changed filters, new columns and CKAN patch releases that touch the DataStore API.
- Minor releases can carry backwards-incompatible changes, so each CKAN minor upgrade is retested before go-live.
- Retainers can cover continuous testing of the search endpoints as your data and queries change.

