Search Stream

The search stream lets you read many objects from acre Access Control in one request, with no paging. Use it when you need to:

  • copy every Person into another system (a full sync),
  • re-read a known list of objects by key, or
  • pull every object of one type.

In the examples, {base} is the regional API address and {folder} is the key of the instance root folder. Every call needs an Authorization: Bearer {token} header.

What it does

A normal list call returns one page of objects as one JSON array. You have to wait for the whole page before you can use any of it.

The search stream works differently. It sends one object per line and sends each line as soon as it has read it from the database. Your code reads a line, handles that object, and moves on to the next. Neither side has to hold the whole result in memory, and you get the first object long before the server finds the last one.

graph LR I["Integration"] -- "filter" --> S["searchstream2"] S --> D[("Objects")] D -- "cursor" --> S S -- "one JSON object
per line" --> I

Each line is a full object, in the same JSON shape you get from a single-object GET. It includes a $type field that tells you the exact type, for example Feenics.Keep.WebApi.Model.PersonInfo, Feenics.Keep.WebApi.Model.

One thing to watch: the response says Content-Type: application/json, but the body is not a JSON array. It is one JSON object per line. Parse each line by itself.

Two endpoints, one behaviour

Endpoint Method Where the query goes
{base}/api/f/{folder}/searchstream GET q query-string parameter
{base}/api/f/{folder}/searchstream2 POST request body, as a JSON string

Both endpoints do the same thing and take the same options. The only difference is where you put the query. searchstream2 exists because a MongoDB filter can be long and full of characters that do not fit well in a URL. Use searchstream2 unless you have a reason not to. The wrapper’s SearchStream class uses it.

The POST body is the query as a JSON string. That means the whole query is wrapped in double quotes, and every quote inside it is escaped with a backslash:

"{ \"_t\": \"Person\", \"Surname\": \"Example\" }"

The query

A query has two parts: an optional type prefix, then the search text.

[type:<TypeName> ]<search>
  • The prefix (type:Person, type:Reader, type:AccessLevel, and so on) limits the search to one object type. Leave it out to search every type.
  • The search text can be one of three things. The first character decides which:
First character Form Matches
{ MongoDB filter Any field, any operator. The full filter language.
/ Regular expression CommonName only.
anything else Text search The collection’s text index (names and similar fields).

You can use the prefix and a MongoDB filter together. But a filter can also say "_t": "Person" itself, which does the same job. So when you use a filter, the prefix is optional.

Options

All options go in the query string. They work the same on both endpoints.

Option Default Meaning
includeChildFolders false Also return objects from folders below {folder}. Set this to true to search the whole instance.
spanScope false Include objects shared from other scopes.
forTags — Repeat once per tag. Only objects that carry all listed tags.
limit none Stop after this many objects.
page, pageSize none Optional. Leave them out to get everything in one response. Set both to get one page at a time, sorted by _id. This is useful if you want to restart a long read from a known point.
hints — Index hints. Not normally needed.

Examples

Each example shows the POST body for searchstream2. Some also show the full curl call. Replace {token}, {base} and {folder} with your own values.

1. Every Person in the instance

Body:

"{ \"_t\": \"Person\" }"
curl -N -X POST "{base}/api/f/{folder}/searchstream2?includeChildFolders=true" \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '"{ \"_t\": \"Person\" }"'

-N tells curl not to buffer output, so you see each line as it arrives. This is the call to use for a full resync.

2. A known list of people by key

Body:

"{ \"_t\": \"Person\", \"_id\": { \"$in\": [ { \"$oid\": \"68a1…\" }, { \"$oid\": \"6899…\" } ] } }"
curl -N -X POST "{base}/api/f/{folder}/searchstream2?includeChildFolders=true" \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '"{ \"_t\": \"Person\", \"_id\": { \"$in\": [ { \"$oid\": \"68a1…\" }, { \"$oid\": \"6899…\" } ] } }"'

Use this to re-read a set of people, for example the ones that Change Tracking said have changed. If a key you asked for does not come back, that person was either deleted or is no longer visible to your user.

3. People whose surname starts with a letter

Body:

"{ \"_t\": \"Person\", \"Surname\": { \"$regex\": \"^Ex\", \"$options\": \"i\" } }"

4. All readers

There is more than one type of reader. To get them all, match several type names with $in:

Body:

"{ \"_t\": { \"$in\": [ \"Reader\", \"MercuryReader\" ] } }"

The type: prefix only takes one type name. When you need more than one, use a filter like this instead.

5. Name search by regular expression

Body:

"type:Person /^Jane/"

The regular expression is matched against CommonName only.

6. Free text

Body:

"type:Person jane example"

This uses the text index. It is a good fit for a search box, but it is less exact than a filter.

7. People with an active card

A card is active when three things are true: ActiveOn is in the past, ExpiresOn is in the future, and IsDisabled is false. $elemMatch makes sure all three are checked against the same card:

Body:

"{ \"_t\": \"Person\", \"CardAssignments\": { \"$elemMatch\": { \"ActiveOn\": { \"$lte\": { \"$date\": \"2026-11-19T00:00:00Z\" } }, \"ExpiresOn\": { \"$gt\": { \"$date\": \"2026-11-19T00:00:00Z\" } }, \"IsDisabled\": false } } }"

Replace both dates with the current time.

8. People with any access level

A Person’s access levels are stored as links in ObjectLinks, each with Relation set to AccessLevel:

Body:

"{ \"_t\": \"Person\", \"ObjectLinks.Relation\": \"AccessLevel\" }"

To find people in one particular access level, add its key:

"{ \"_t\": \"Person\", \"ObjectLinks\": { \"$elemMatch\": { \"Relation\": \"AccessLevel\", \"LinkedObjectId\": { \"$oid\": \"{accessLevelKey}\" } } } }"

9. Objects that carry tags

curl -N -X POST "{base}/api/f/{folder}/searchstream2?includeChildFolders=true&forTags=contractor&forTags=site-a" \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '"{ \"_t\": \"Person\" }"'

This returns people that have both tags, not either one.

10. The same call on searchstream (GET)

curl -N -G "{base}/api/f/{folder}/searchstream" \
  -H "Authorization: Bearer {token}" \
  --data-urlencode 'q={ "_t": "Person", "Surname": "Example" }' \
  --data-urlencode 'includeChildFolders=true'

-G together with --data-urlencode puts q in the query string and encodes it correctly for you.

Using the wrapper

In the .NET wrapper, you create the stream once and then read it in a loop. (See Data Streams for the full wrapper guide, which also covers EventsStream and AggregateStream.)

using var stream = await SearchStream.Create(client, folder, "{ '_t': 'Person' }", includeChildFolders: true);
while (await stream.ReadAsync())
{
    var person = stream.BaseInfo as PersonInfo;
    // process one object
}

Create calls searchstream2 for you. BaseInfo is null until the first ReadAsync returns. You can use single quotes inside the filter string; the wrapper accepts relaxed JSON.

Reading the response

  • Read the body one line at a time. Do not wait for the end and then parse everything as one document.
  • Each line is one object. Look at its $type field (or the _t array, if you asked for it) to decide which model to map it to.
  • Objects your user is not allowed to see are left out. The stream does not tell you that anything was skipped.
  • If the connection drops part-way, start again using page and pageSize, or make the filter narrower. Results are only sorted by _id when you supply page and pageSize.
  • Many HTTP clients time out after 100 seconds by default. For a full resync of a large instance, set a longer timeout, or none at all.

Good to know

  • In a filter, write _id values as { "$oid": "…" } and dates as { "$date": "2026-11-19T00:00:00Z" }.
  • A filter that is not valid JSON gets a “bad request” reply. Remember the rule: {…} is a filter, /…/ is a name pattern, and anything else is treated as free text.
  • The stream returns the same objects as the paged search endpoint. Use search when the result is small and known (for example, one object by key). Use the stream when the result might be large.
  • The stream gives you each object as it is now. It does not tell you what changed or when. For that, use the Events collection. See Change Tracking.