Search
Confused about "Search"?
Let us know how we can improve our documentation:
Message search is built-in to the chat API. You can enable and/or disable the search indexing on a per channel type through the Stream Dashboard.
The command shown below selects the channels in which John is a member. Next, it searches the messages in those channels for the keyword “'supercalifragilisticexpialidocious'”.
Query Parameters
Copied!Confused about "Query Parameters"?
Let us know how we can improve our documentation:
name | type | description | default | optional |
---|---|---|---|---|
filter_conditions | object | Filter conditions for channels. We will only ever search a maximum of 500 channels at a time, so it is beneficial to make these filters as strict as possible. See the Query Channels section for information about these filters. | - | |
message_filter_conditions | object | Filter conditions for messages. See the next section for details. You must either specify query or message_filter_conditions. | - | ✓ |
query | string | A string to search for (which is a full text search). This is equivalent passing {text: {$q: <query>}} to message_filter_conditions. You must either specify query or message_filter_conditions. | - | ✓ |
limit | integer | The number of messages to return. | 100 | ✓ |
offset | integer | The pagination offset. See the Pagination section for more information. You cannot use a non-zero offset with the sort or the next parameters. | 0 | ✓ |
sort | object or array of objects | The sorting used for the messages matching the filters. Sorting is based on field and direction, and multiple sorting options can be provided. Direction can be ascending (1) or descending (-1). | [{relevance: -1}, {id: 1}] | ✓ |
next | string | A key used to paginate. See the Pagination section for more information. | - | ✓ |
Message Filter Conditions
Copied!Confused about "Message Filter Conditions"?
Let us know how we can improve our documentation:
You can use following operators and fields in order to search messages:
Field | Description | Allowed operators |
---|---|---|
id | message ID | $eq, $gt, $gte, $lt, $lte, $in |
text | text of the message | $q. $autocomplete, $eq, $gt, $gte, $lt, $lte, $in |
type | type of the message. Messages with type 'system' and 'deleted' are excluded from results. | $eq, $gt, $gte, $lt, $lte, $in |
parent_id | the parent message ID (if the message is a reply) | $eq, $gt, $gte, $lt, $lte, $in |
reply_count | number of replies the message has | $eq, $gt, $gte, $lt, $lte, $in |
attachments | whether or not the message contains an attachment | $exists, $eq, $gt, $gte, $lt, $lte, $in |
attachments.type | the type of the attachment | $eq, $in |
mentioned_users.id | user ID that is included in the message's mentions | $contains |
user.id | user ID of the user that sent the message | $eq, $gt, $gte, $lt, $lte, $in |
created_at | created at time | $eq, $gt, $gte, $lt, $lte, $in |
updated_at | updated at time | $eq, $gt, $gte, $lt, $lte, $in |
pinned | whether the message has been pinned | $eq |
<custom field> | any custom field that is attached to your message | $eq, $gt, $gte, $lt, $lte, $in |
Sorting
Copied!Confused about "Sorting"?
Let us know how we can improve our documentation:
Messages default to being sorted by relevance to your query, with the message ID as a tie-breaker for any equally relevant results. If your query does not use the $q or $autocomplete operators then all results are considered equally relevant.
You can sort by any of the filter-able fields, including custom fields. Custom fields that are numbers will be sorted numerically, while custom string fields will be sorted lexicographically. See the Pagination section for examples of sorting.
Pagination
Copied!Confused about "Pagination"?
Let us know how we can improve our documentation:
There are two ways to paginate through search results:
Version 1 - Using limit and offset
Version 2 - Using limit and next/previous values
Limit and offset will allow you to access up to 1000 results matching your query. You will not be able to sort using limit and offset. The results will instead be sorted by relevance and message ID. See the code at the top of the page for examples of limit and offset pagination.
Next pagination will allow you to access all search results that match your query, and you will be able to sort using any filter-able fields and custom fields.
Pages of sort results will be returned with next and previous strings, which tell the API where to start searching from and what sort order to use. You can supply those values as a next parameter when making a query to get a new page of results.