Esc
ZeroIndex
GuidesAPI referenceSDKsChangelogOverviewBuy ZeroIndex

Search

View as MarkdownThe page as plain text

Search an index and get ranked, typo tolerant results, with optional filters, facets and highlights.

POST/v1/indexes/{uid}/search

Works with admin keys and search keys. A scoped search key adds its own filter to every query.

Path parameters

uidstringrequired

The name of the index.

Body

qstringdefault ""

The query. An empty query returns every document, ranked.

filterstring

Only return documents that match. See Filters.

sortstring[]

Sort by fields instead of relevance, like ["price:asc"].

facetsstring[]

Fields to count values for. See Faceted search.

limitintegerdefault 20

How many hits to return, up to 1,000.

offsetintegerdefault 0

How many hits to skip.

attributesToHighlightstring[]

Fields to return in _formatted with matching words wrapped in <mark>.

Response

hitsobject[]

The matching documents, best first.

estimatedTotalHitsinteger

About how many documents match. Exact up to 1,000.

facetDistributionobject

Counts for each facet value, when you ask for facets.

processingTimeMsinteger

How long the search took on the server.

Request

curl https://api.zeroindex.test/v1/indexes/products/search \
  -H "Authorization: Bearer $ZEROINDEX_KEY" \
  -d '{
    "q": "wireless hedphones",
    "filter": "in_stock = true",
    "limit": 2
  }'
const results = await client.index("products").search("wireless hedphones", {
  filter: "in_stock = true",
  limit: 2,
});
results = client.index("products").search("wireless hedphones", {
    "filter": "in_stock = true",
    "limit": 2,
})

Response

200
{
  "hits": [
    {
      "id": 1042,
      "name": "Wireless headphones",
      "price": 99,
      "_formatted": { "name": "<mark>Wireless</mark> <mark>headphones</mark>" }
    },
    {
      "id": 1187,
      "name": "Wireless earbuds",
      "price": 79,
      "_formatted": { "name": "<mark>Wireless</mark> earbuds" }
    }
  ],
  "query": "wireless hedphones",
  "estimatedTotalHits": 24,
  "limit": 2,
  "offset": 0,
  "processingTimeMs": 4
}