Docs

Legacy search

Full-text search across a project with /v2/api/search and /v3/api/search.

View as Markdown
curl 'https://cdn.capacms.com/v2/api/search?q=preview' -H "x-api-key: $CAPA_KEY"
{
  "data": [
    { "id": "61001acc-e032-48cb-aeff-0f2d0bb69e6b", "title": "A Preview You Can Trust" },
    { "id": "7dd101af-5a84-4d46-8c52-f2227ec42f82", "title": "Pages Are a Map, Not a Tree" },
    { "id": "49583221-3d95-440a-9ea0-962100e1629d", "title": "The Edit Is the Product" }
  ],
  "meta": { "total": 3, "totalPages": 1, "currentPage": 1, "limit": 50,
            "hasNextPage": false, "hasPrevPage": false }
}

Search is full text with typo tolerance (q=previw finds the same three), ranked by relevance. It covers every model marked Searchable Model in the admin, which a new model is by default. Each hit is the entry id and its title value, or "" when the entry has no title field.

ParameterDefaultRangeNotes
qrequiredtrimmed. Empty or blank answers 200 with no results. Missing answers 500
size501 to 500results per page. Above 500 is 500. 0 or text is 50
page11 and up
modelNamespaceall modelslimit hits to one model. An unknown namespace finds nothing
extendedoffany non-empty value, even false, returns full entries. Leave it out or empty to get { id, title } hits
depth00 to 4with extended, as on a list
nestedLimit, nestedPage100, 1with extended, as on a list
structurerelationsrelations, treev2 only, with extended
relatedFiltersnonewith extended: JSON only. The relationFilter. form is not read here

A pk_ key finds published entries only. An sk_ key also finds drafts, and matches their newest text.

Things to know before you build on it:

  • A published entry that has a newer, unpublished draft is not found by a pk_ key. Search indexes the newest version, and that version is a draft. The entry comes back once the draft is published or discarded.
  • With extended, meta stops describing the whole result. total is the number of hits on this page and hasNextPage is false. Page through extended results by asking for the next page until one comes back shorter than size.
  • With extended, results are not in relevance order. They come back in database order. Search without extended when order matters.
  • Extended results carry the entry's full dataModel and a lastUpdatedByUser key that is always null. The key stays so existing parsers keep working. No editor's email, name or avatar is returned. lastUpdatedBy, the id of whoever last saved the entry, is still there.
  • On /v2/api, an extended hit read with depth=1 or more also carries internal keys that start with _, such as _includedRelationIds: {}. Ignore them. /v3/api removes them.
  • Search responses carry no cache headers of their own.