# Search and filter within dataset

### Datastore search&#x20;

This API allows you to search for data within a dataset or scan through the rows of the dataset in a paginated manner.&#x20;

{% hint style="info" %}
Note that the following API uses the domain: <https://data.gov.sg>

For example:&#x20;

<https://data.gov.sg/api/action/datastore_search>

If you're looking to query the following dataset:\
<https://data.gov.sg/datasets/d_8b84c4ee58e3cfc0ece0d773c8ca6abc/view>\
\
Please refer to the URL from the dataset page, taking the dataset\_id (starting with d\_...), and passing that into your datastore search API query as shown below:\
\
<https://data.gov.sg/api/action/datastore_search?resource_id=d_8b84c4ee58e3cfc0ece0d773c8ca6abc>

\
\
For staging, note that the dataset\_id on production and staging might differ:

* Domain: <https://api-public-staging.data.gov.sg/>
* Example: <https://api-public-staging.data.gov.sg/api/action/datastore_search?resource_id=d_8b84c4ee58e3cfc0ece0d773c8ca6abc>
  {% endhint %}

### Search Rows in Dataset

## GET /api/action/datastore\_search

> Search rows in a dataset

```json
{"openapi":"3.0.0","info":{"title":"Data.gov.sg APIs","version":"1.0.0"},"servers":[{"url":"https://data.gov.sg"}],"paths":{"/api/action/datastore_search":{"get":{"summary":"Search rows in a dataset","description":"","parameters":[{"name":"resource_id","in":"query","description":"ID or alias of the resource to be searched against. This corresponds to the dataset_id (resource_id is a legacy reference)","required":true,"schema":{"type":"string"}},{"name":"limit","in":"query","description":"Maximum number of rows to return (optional, default: 100)","required":false,"schema":{"type":"integer","default":100}},{"name":"offset","in":"query","description":"Offset this number of rows (optional)","required":false,"schema":{"type":"integer"}},{"name":"fields","in":"query","description":"Fields to return (optional, default: all fields in original order)","required":false,"schema":{"type":"string"}},{"name":"filters","in":"query","description":"Dictionary of matching conditions, e.g {\"key1\": \"a\", \"key2\": \"b\"}","required":false,"schema":{"type":"string"}},{"name":"q","in":"query","description":"Example: {\"columnName\": \"columnValue\"}","required":false,"schema":{"type":"string"}},{"name":"sort","in":"query","description":"Comma-separated field names with ordering, eg.: \"fieldname1, fieldname2 desc\"","required":false,"schema":{"type":"string"}}],"responses":{"200":{"description":"Fetched data","content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/CkanDatastoreSearch"},{}]}}}},"429":{"description":"Rate limit exceeded","content":{"application/json":{"schema":{"type":"object","properties":{"code":{"type":"number"},"name":{"type":"string"},"data":{"type":"object"},"errorMsg":{"type":"string"}}}}}},"default":{"description":"Error information","content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/CkanError"},{}]}}}}}}}},"components":{"schemas":{"CkanDatastoreSearch":{"allOf":[{"$ref":"#/components/schemas/CkanBase"},{"type":"object","required":["result"],"properties":{"result":{"type":"object","description":"Resource","required":["resource_id","fields","records"],"properties":{"resource_id":{"type":"string","description":"Resource id"},"fields":{"type":"array","description":"Data fields","items":{"type":"object","description":"Data field"}},"records":{"type":"array","description":"Data rows","items":{"type":"object","description":"Data row in object format"}},"limit":{"type":"integer","description":"Limit for number of rows returned"},"total":{"type":"integer","description":"Total number of rows"},"_links":{"type":"object","description":"Pagination-related links","properties":{"start":{"type":"string","description":"Link back to first page"},"next":{"type":"string","description":"Link to next page"}}}}}}}]},"CkanBase":{"type":"object","required":["success"],"properties":{"success":{"type":"boolean","description":"Whether fetch is succesfully"}}},"CkanError":{"allOf":[{"$ref":"#/components/schemas/CkanBase"},{"type":"object","required":["error"],"properties":{"error":{"type":"object","description":"Error type and description"}}}]}}}}
```
