# Pipelines

{% hint style="info" %}
Pipeline aggregation allows for querying, aggregating, and transforming data in multiple stages in real-time through a single API request. While query arguments allow for making simple, single-stage queries through the API, pipelines allow for more complex searches, aggregations and transformations.
{% endhint %}

To leverage pipeline aggregation via the API, simply pass a pipeline query argument with the request. The pipeline query argument is an array of pipeline stages that execute in order. Each stage transforms the result set and passes it on to the next stage in the pipeline.

```
?pipeline=[{ stage1 },{ stage2 }, { stage3 }, ...]
```

| Name         | Description                                                                                                                                                                                     |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `$group`     | Outputs a cursor containing specified groups of elements from the previous cursor. Groups may make use of accumulator expressions.                                                              |
| `$limit`     | Outputs a cursor containing a limited number of elements from the previous cursor                                                                                                               |
| `$match`     | Outputs a cursor containing a subset of elements from the previous cursor which satisfy a set matching criteria.                                                                                |
| `$project`   | A JSON object that specifies existing properties or new properties to pass along to the next stage in the pipeline.                                                                             |
| `$skip`      | An integer representing the number of results to skip. Useful for paging where mapping or groupings have been applied, or where search the search criteria cannot be paged using unique fields. |
| `$sort`      | A JSON object containing one or more properties, the values of which must be 1 for ascending and -1 for descending                                                                              |
| `$count`     | Exhausts an input cursor and outputs a cursor with a single element specifying the total number of elements within the input cursor.                                                            |
| `$cursor`    | Outputs a cursor containing the results of a database query and exhausts any previous cursors to dev/null                                                                                       |
| `$output`    | N/A                                                                                                                                                                                             |
| `$transform` | N/A                                                                                                                                                                                             |
| `$var`       | N/A                                                                                                                                                                                             |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.medable.com/cortex-api/expressions/pipelines.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
