The call
GET /api/collections/{name}/search
| Name | Type | What it does |
|---|---|---|
q | string | Required. What to find: plain text, matched literally and ignoring case; with regex=1, a regular expression (syntax). |
regex | 1 | Optional. Read q as a regular expression. |
filter | string | Optional. Only documents whose metadata has these values: key:value terms separated by spaces, all of which must hold. |
limit | integer | Optional. How many documents to return: 20 unless you ask, up to your plan's most (plans). |
Shell
curl -G https://stackgrep.com/api/collections/contracts/search \
-H "Authorization: Bearer $STACKGREP_KEY" \
--data-urlencode 'q=terminat\w+ for convenience' -d regex=1 \
-d filter=customer:acme -d limit=5Response
{"collection": "contracts", "took_ms": 6.4, "docs": 48210,
"hits": [
{"id": "acme/msa-2024.txt", "match": "terminate for convenience",
"line": "12.2 Either party may terminate for convenience on 90 days' written notice.",
"meta": {"customer": "acme", "year": "2024", "signed": "true"}}
]}The answer
| Name | Type | What it does |
|---|---|---|
hits[].id | string | The document's id: read it whole with it. |
hits[].match | string | The text that matched. |
hits[].line | string | The line around the match, so an agent can often answer from the result alone. |
hits[].meta | object | The document's metadata. |
docs | integer | Documents in the collection's index, older versions included until compaction. |
took_ms | number | Time spent searching, in milliseconds. |
Each document shows up once, with its first match; the newest version of each document is the only one searched. A search costs 1 credit.
Need to know how many documents match, not just the first few? Use count.
Try it on your own documentsExact and regex search for your agents, from one API. Or see the engine on npm's source first.