> ## Documentation Index
> Fetch the complete documentation index at: https://docs.magpiedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Magpie is a trace store for AI agents, used as a library (crate `magpiedb`, npm `magpiedb`, PyPI `magpiedb`) or as `magpie-server`, which takes OpenTelemetry (OTLP over HTTP on 127.0.0.1:4318 and gRPC on 127.0.0.1:4317 by default).
> Use only the commands, flags, routes and JSON shapes that these pages show. Do not guess a flag or a query field: if a page does not show it, say that the docs do not show it.
> Packages and server binaries are not published yet: build from source, as the quick start shows. Check the status note on the introduction page before you suggest `cargo add`, `npm install` or `pip install`.
> Only one process may write to a store folder at a time. For many apps, send traces to one `magpie-server`.

# Find text

> Search the input and output of spans with words, phrase, contains and prefix, and search error messages.

`text` looks in the `input` and the `output` of a span. There are four kinds. The examples use the [sample data](https://docs.magpiedb.com/queries/overview.md#the-sample-data).

**`words`**: every word, in any order. The newest spans come first (`sort: "newest"` is the default).

```sh theme={null}
curl -s localhost:4318/v1/search -d '{"filter": {"text": {"words": "refund"}}, "limit": 3}'
```

```json theme={null}
{"spans":[{"traceId":"t3","spanId":"tl3","startedAt":3100},{"traceId":"t3","spanId":"r3","startedAt":3000},{"traceId":"t2","spanId":"m2","startedAt":2100}],"nextCursor":"eyJsaXN0Ijoic3BhbnMiLCJzb3J0IjoibmV3ZXN0IiwidGltZSI6MjEwMCwiaWQiOiJtMiIsImlkMiI6InQyIiwibiI6MX0"}
```

**`phrase`**: the words next to each other, in this order. `m2` has "policy refund", so it is not found.

```sh theme={null}
curl -s localhost:4318/v1/search -d '{"filter": {"text": {"phrase": "refund policy"}}, "limit": 10}'
```

```json theme={null}
{"spans":[{"traceId":"t1","spanId":"m1","startedAt":1100},{"traceId":"t1","spanId":"r1","startedAt":1000}],"nextCursor":null}
```

With `words`, each word can be in another place: `m2` is found too.

```sh theme={null}
curl -s localhost:4318/v1/count -d '{"filter": {"text": {"words": "refund policy"}}}'
```

```json theme={null}
{"count":3}
```

**`contains`**: a piece inside a word, like SQL `LIKE '%efun%'`. Upper and lower case are the same.

```sh theme={null}
curl -s localhost:4318/v1/count -d '{"filter": {"text": {"contains": "efun"}}}'
```

```json theme={null}
{"count":5}
```

With a space, the first piece is the end of a word and the last piece is the start of a word. `fund pol` is in "refund policy" (`r1`, `m1`), not in "policy refund" (`m2`):

```sh theme={null}
curl -s localhost:4318/v1/count -d '{"filter": {"text": {"contains": "fund pol"}}}'
```

```json theme={null}
{"count":2}
```

**`prefix`**: whole words, and the last word may go on. `look` finds "lookup":

```sh theme={null}
curl -s localhost:4318/v1/count -d '{"filter": {"text": {"prefix": "look"}}}'
```

```json theme={null}
{"count":2}
```

## Errors

`text` does not look in the error message of a span. Use `errorText`, with the same four kinds. `tl1` failed with "timeout":

```sh theme={null}
curl -s localhost:4318/v1/count -d '{"filter": {"errorText": {"words": "timeout"}}}'
```

```json theme={null}
{"count":1}
```

## What a word is

* Letters and digits with no space between them are found together, in their order: `e-mail` is `e` next to `mail`, and `user@example.com` is that address.
* Thai, Lao, Khmer, Burmese and Korean have no spaces between words. Magpie finds a run of these characters as pairs of characters. Chinese and Japanese are found too.
* A word of up to 255 bytes (a hash, an id) is found. A word of 256 bytes or more stays in the stored text, but no text search finds it.
* Limits of `contains` and `prefix` (a short piece is slow; a piece that matches more than 16,384 words in one part of the store is refused): see [limits](https://docs.magpiedb.com/limits.md#text-search).

> [card] [Filter spans](https://docs.magpiedb.com/queries/filters.md)
>
> Put text together with kind, time, tag and attributes.

> [card] [Queries overview](https://docs.magpiedb.com/queries/overview.md)
>
> The sample data and the routes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.