# Stop Search API (/api/using-the-api/stop-search-api)

Since V1 of the API, a new [stop search endpoint](/api/stops/searchStops) is available. This endpoint allows searching across
all stop documents (including unassigned stops), within your permitted data lifecycle.

The endpoint features full-text keyword search as well as a filtering DSL for including or excluding documents
from the search.

## Keywords

The most basic use of search is to simply provide keywords with the `keyword` parameter.
This will perform a fuzzy full-text search across all applicable text fields in the stop
documents and return the results sorted by relevance (by default).

For example:

`?keyword=london`

## Filtering DSL

Filtering is performed with a simple, SQL-inspired language. It allows for precise queries
using comparison operators and boolean logic.

For example (non-url-encoded for clarity):

`?filter=address.placeId != "ChIJj61dQgK6j4AR4GeTYWZsKWw" and address.countryCode = "DE"`

### Syntax Overview

A filter expression consists of a field path, a comparison operator, and a value:

`[field] [operator] [value]`

Multiple expressions can be combined using boolean operators:

`[condition1] and ([condition2] or [condition3])`

> **Note on encoding: These expressions should be url-encoded before being passed to the API**:

---

### Supported Data Types

The DSL uses strictly typed fields and values. The following table describes the available data types and how to represent them in a filter string.

| Type        | Description                                             | Examples                                 |
| :---------- | :------------------------------------------------------ | :--------------------------------------- |
| **String**  | Text values enclosed in **double quotes**.              | `"active"`, `"John Doe"`, `"2026-01-01"` |
| **Integer** | Whole numbers, positive or negative.                    | `123`, `-10`, `0`                        |
| **Float**   | Decimal numbers, positive or negative.                  | `123.45`, `-33.8688`                     |
| **Boolean** | Logical values `true` or `false`. Case-insensitive.     | `true`, `FALSE`, `True`                  |
| **Null**    | Represents an empty or missing value. Case-insensitive. | `null`, `NULL`                           |

---

### Comparison Operators

The following operators are available for comparing fields against values.

| Operator | Name             | Description                                                 | Supported Types    |
| :------- | :--------------- | :---------------------------------------------------------- | :----------------- |
| `=`      | Equals           | Field value exactly matches the provided value.             | All types          |
| `!=`     | Not Equals       | Field value does not match the provided value.              | All types          |
| `~=`     | Phrase Match     | Field value contains the provided string (substring match). | String             |
| `>`      | Greater Than     | Field value is strictly greater than the provided value.    | String, Int, Float |
| `>=`     | Greater or Equal | Field value is greater than or equal to the provided value. | String, Int, Float |
| `<`      | Less Than        | Field value is strictly less than the provided value.       | String, Int, Float |
| `<=`     | Less or Equal    | Field value is less than or equal to the provided value.    | String, Int, Float |

> **Note on String Comparisons**: The operators `>`, `>=`, `<`, and `<=` can only be used with ISO-8601 date strings (e.g., `createdAt > "2026-01-01"`).

---

### Boolean Operators

Boolean operators allow you to combine multiple comparison filters into complex queries.

| Operator | Description                                    | Precedence |
| :------- | :--------------------------------------------- | :--------- |
| `and`    | Returns true if both conditions are met.       | 2 (Higher) |
| `or`     | Returns true if at least one condition is met. | 1 (Lower)  |

_Operators are case-insensitive (`AND`, `and`, `And` are all valid)._

### Grouping and Precedence

By default, `and` has higher precedence than `or`. You can use **parentheses `()`** to group conditions and override this behaviour.

- `a = 1 or b = 2 and c = 3` is evaluated as `a = 1 or (b = 2 and c = 3)`.
- `(a = 1 or b = 2) and c = 3` forces the `or` condition to be evaluated first.

---

### Fields and Paths

Fields represent the attribute of the resource you are filtering.

- **Nested Fields**: Use dot notation to access nested attributes (e.g., `address.countryCode`).

### Custom Properties

Teams can create custom properties for stops. These can be used in filters via the
custom property's ID (not the name) as a nested field.

For example:

```
custom_property.0234-5678-0abc-def3 = "value"
```

To know the ID of a custom property, use the [custom properties list endpoint](/api/team/listCustomStopProperties).

---

### Data Freshness

Note that data is ingested into the search index more slowly than the realtime API. This means a
stop may not be immediately available in the search index after it is created. If you need to fetch
a stop immediately, you should always use the stop restful resources e.g. [fetch stop](/api/stops/getStop)

### Examples

The following are examples of valid, parsable filter strings (field names are examples and may not valid for stops):

- **Simple Equality**: `address.countryCode = "DE"` - return all stops where the countryCode is exactly "DE".
- **Numeric Comparison**: `address.latitude >= 100` - return all stops where the latitude is greater than or equal to 100.
- **Substring Search**: `address ~= "London"` - return all stops where the address contains "London".
- **Null Check**: `arrivalTime = null` - return all stops where the arrivalTime field is not set.
- **Boolean Check**: `deliveryInfo.attempted = true` - return all stops where deliveryInfo.attempted is set to true.
- **Combined Logic**: `address ~= "London" and address.countryCode = "GB"` - return all stops where the address contains "London" and the country code is "GB".
- **Multiple Options**: `address ~= "London" or address ~= "Bristol" or address ~= "Manchester"` - return all stops where the address contains either London, Bristol or Manchester.
- **Complex Grouping**: `(address ~= "London" or address ~= "Manchester") and (createdAt >= "2026-05-01T00:00:00Z" and createdAt < "2026-05-02T00:00:00Z")` - return all stops where the address contains London or Manchester that were created on 2026-05-01.
- **Date Range**: `createdat >= "2026-05-01T00:00:00Z" and createdAt < "2026-06-01T00:00:00Z"` - return all stops created in May 2026.

For code samples see [Searching Stops](/docs/api-examples/search-stops)