Search & metadata

Typesense pagination

Page through a Typesense result set.

The page and per_page parameters control how search results are divided into manageable chunks. This is essential for handling large datasets efficiently and improving application performance.

Quick start

Here’s how to get the first 25 transactions:

curl -X POST "http://localhost:5001/search/transactions" \
  -H "X-blnk-key: <api-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "q": "*",
    "page": 1,
    "per_page": 25
  }'
const response = await blnk.Search.search(
  {
    q: "*",
    page: 1,
    per_page: 25,
  },
  'transactions',
);
results, _, _ := client.Search.SearchDocument(
    blnkgo.SearchParams{Q: "*", Page: 1, PerPage: 25},
    blnkgo.Transactions,
)
response = blnk.search.search(
  {
    "q": "*",
    "page": 1,
    "per_page": 25,
  },
  "transactions",
)
ApiResponse<JsonNode> response = blnk.search().search(
    SearchParams.create()
        .q("*")
        .page(1)
        .perPage(25),
    "transactions");

Pagination parameters

ParameterDescriptionDefaultRange/LimitType
pageSpecifies which page of results to retrieve1Minimum: 1integer
per_pageNumber of records returned in each page10Maximum: 250integer
# Examples
{
  "page": 1,        # First page (default)
  "per_page": 50    # 50 results per page
}

{
  "page": 3,        # Third page
  "per_page": 250   # Maximum results per page
}

Common pagination patterns

Basic pagination

Start with the first page and a reasonable page size.

curl -X POST "http://localhost:5001/search/transactions" \
  -H "X-blnk-key: <api-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "q": "*",
    "page": 1,
    "per_page": 50
  }'
const response = await blnk.Search.search(
  {
    q: "*",
    page: 1,
    per_page: 50,
  },
  'transactions',
);
results, _, _ := client.Search.SearchDocument(
    blnkgo.SearchParams{Q: "*", Page: 1, PerPage: 50},
    blnkgo.Transactions,
)
response = blnk.search.search(
  {
    "q": "*",
    "page": 1,
    "per_page": 50,
  },
  "transactions",
)
ApiResponse<JsonNode> response = blnk.search().search(
    SearchParams.create()
        .q("*")
        .page(1)
        .perPage(50),
    "transactions");

Navigate to specific page

Jump to a specific page when you know the approximate location of your data.

curl -X POST "http://localhost:5001/search/balances" \
  -H "X-blnk-key: <api-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "q": "*",
    "page": 5,
    "per_page": 100
  }'
const response = await blnk.Search.search(
  {
    q: "*",
    page: 5,
    per_page: 100,
  },
  'balances',
);
results, _, _ := client.Search.SearchDocument(
    blnkgo.SearchParams{Q: "*", Page: 5, PerPage: 100},
    blnkgo.Balances,
)
response = blnk.search.search(
  {
    "q": "*",
    "page": 5,
    "per_page": 100,
  },
  "balances",
)
ApiResponse<JsonNode> response = blnk.search().search(
    SearchParams.create()
        .q("*")
        .page(5)
        .perPage(100),
    "balances");

Large result sets

Use maximum page size for bulk data processing.

curl -X POST "http://localhost:5001/search/transactions" \
  -H "X-blnk-key: <api-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "q": "*",
    "filter_by": "created_at:[1720310400..1720396800]",
    "page": 1,
    "per_page": 250
  }'
const response = await blnk.Search.search(
  {
    q: "*",
    filter_by: "created_at:[1720310400..1720396800]",
    page: 1,
    per_page: 250,
  },
  'transactions',
);
results, _, _ := client.Search.SearchDocument(
    blnkgo.SearchParams{Q: "*", FilterBy: "created_at:[1720310400..1720396800]", Page: 1, PerPage: 250},
    blnkgo.Transactions,
)
response = blnk.search.search(
  {
    "q": "*",
    "filter_by": "created_at:[1720310400..1720396800]",
    "page": 1,
    "per_page": 250,
  },
  "transactions",
)
ApiResponse<JsonNode> response = blnk.search().search(
    SearchParams.create()
        .q("*")
        .filterBy("created_at:[1720310400..1720396800]")
        .page(1)
        .perPage(250),
    "transactions");

Combined with sorting

Paginate through sorted results for consistent ordering across pages.

curl -X POST "http://localhost:5001/search/transactions" \
  -H "X-blnk-key: <api-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "q": "*",
    "sort_by": "created_at:desc",
    "page": 2,
    "per_page": 20
  }'
const response = await blnk.Search.search(
  {
    q: "*",
    sort_by: "created_at:desc",
    page: 2,
    per_page: 20,
  },
  'transactions',
);
results, _, _ := client.Search.SearchDocument(
    blnkgo.SearchParams{Q: "*", SortBy: "created_at:desc", Page: 2, PerPage: 20},
    blnkgo.Transactions,
)
response = blnk.search.search(
  {
    "q": "*",
    "sort_by": "created_at:desc",
    "page": 2,
    "per_page": 20,
  },
  "transactions",
)
ApiResponse<JsonNode> response = blnk.search().search(
    SearchParams.create()
        .q("*")
        .sortBy("created_at:desc")
        .page(2)
        .perPage(20),
    "transactions");

Response structure

The pagination information is included in every search response:

{
  "found": 1247,
  "hits": [
    // ... result objects
  ],
  "out_of": 5000,
  "page": 2,
  "request_params": {
    "per_page": 50
  },
  "search_time_ms": 3
}

Key response fields

FieldDescriptionType
foundNumber of records matching your search criteriainteger
out_ofTotal number of records in the collectioninteger
pageCurrent page numberinteger
hitsArray of result objects for the current pagearray

Best practices

  • Start with reasonable page sizes: Use 20-50 records for UI display, 100-250 for data processing.
  • Always sort paginated results: Use sort_by to ensure consistent ordering across pages.
  • Handle empty pages gracefully: Check if hits array is empty before processing results.
  • Monitor performance: Larger page sizes may impact response time.