Skip to content
Nikita Ganzikov edited this page Jan 9, 2026 · 2 revisions

Search

Search for documents in your indexes using powerful query syntax.

Search Endpoint

Endpoint: POST /indexes/:id/searches

Query Parameters:

Parameter Type Default Description
q string "" Search query (empty = match all)
offset int 0 Number of results to skip
limit int 20 Maximum results per page
page int 1 Page number (alternative to offset)
sort[] array ["-_score"] Sort fields (prefix with - for descending)
attributesToRetrieve[] array all Fields to include in results
attributesToExclude[] array none Fields to exclude from results

Basic Search

Search all documents:

curl -X POST "http://localhost:3000/indexes/products/searches"

Search with query:

curl -X POST "http://localhost:3000/indexes/products/searches?q=laptop"

Pagination

Using limit and offset:

curl -X POST "http://localhost:3000/indexes/products/searches?q=laptop&limit=20&offset=40"

Using page:

curl -X POST "http://localhost:3000/indexes/products/searches?q=laptop&limit=20&page=3"

Sorting

Sort by field (ascending):

curl -X POST "http://localhost:3000/indexes/products/searches?sort[]=price"

Sort by field (descending):

curl -X POST "http://localhost:3000/indexes/products/searches?sort[]=-price"

Multiple sort fields:

curl -X POST "http://localhost:3000/indexes/products/searches?sort[]=category&sort[]=-price"

Using POST body:

curl -X POST "http://localhost:3000/indexes/products/searches" \
  -H "Content-Type: application/json" \
  -d '{
    "q": "laptop",
    "sort": ["category", "-price", "-_score"]
  }'

Special Sort Fields:

  • _score - Relevance score (default: descending)
  • _id - Document ID

Sort Order:

  • Prefix field name with - for descending order
  • No prefix means ascending order
  • Results are sorted by the first field, then by subsequent fields for ties
  • All fields in the sort order MUST be indexed

Attribute Filtering

Include only specific fields:

curl -X POST "http://localhost:3000/indexes/products/searches?attributesToRetrieve[]=name&attributesToRetrieve[]=price"

Exclude specific fields:

curl -X POST "http://localhost:3000/indexes/products/searches?attributesToExclude[]=description&attributesToExclude[]=internal_notes"

Note: You cannot use both attributesToRetrieve[] and attributesToExclude[] in the same request.

Response Format

{
  "hits": [
    {
      "id": "1",
      "name": "Laptop",
      "price": 999.99,
      "category": "electronics"
    }
  ],
  "totalHits": 42,
  "totalPages": 3
}

Response Fields:

  • hits - Array of matching documents
  • totalHits - Total number of matches
  • totalPages - Total number of pages (based on limit)

Advanced Queries

See Query Syntax for detailed query syntax documentation.

Field-specific search:

curl -X POST "http://localhost:3000/indexes/products/searches?q=name:laptop"

Boolean queries:

curl -X POST "http://localhost:3000/indexes/products/searches?q=laptop AND price:<1000"

Phrase search:

curl -X POST "http://localhost:3000/indexes/products/searches?q=\"gaming laptop\""

Wildcard search:

curl -X POST "http://localhost:3000/indexes/products/searches?q=lap*"

Clone this wiki locally