--- title: About the query pipeline routing algorithm slug: '1507' canonical_url: https://docs.coveo.com/en/1507/ collection: tune-relevance source_format: adoc --- # About the query pipeline routing algorithm When a [query](https://docs.coveo.com/en/231/) is sent to the Search API, a routing algorithm is executed to determine which [query pipeline](https://docs.coveo.com/en/180/) in the target [Coveo organization](https://docs.coveo.com/en/185/) will process this query. The following diagram illustrates the process of a query being routed to a query pipeline.[.footnote]^[[1](#last-pipeline-organization)]^ ![Query Pipeline Routing Algorithm](https://docs.coveo.com/en/assets/images/tune-relevance/routing-algorithm.png) -- 1. The **Last pipeline in organization** refers to the pipeline whose `position` attribute is the highest of all the query pipelines in the Coveo organization. -- When a query is sent to the Search API: . [[step1]]If the [search token](https://docs.coveo.com/en/1346/) enforces a pipeline, go to [Step 4](#step4) using the [search token-enforced pipeline](https://docs.coveo.com/en/1666#search-token-enforced-routing) (bypassing its condition, if any). . [[step2]]Otherwise, if the search interface enforces a pipeline, go to [Step 4](#step4) using the [search interface-enforced pipeline](https://docs.coveo.com/en/1666#search-interface-enforced-routing) (bypassing its condition, if any). . [[step3]]Otherwise, for each pipeline that has a condition in the Coveo organization: .. [[step3a]]If the query meets the condition, go to [Step 4](#step4) using the current pipeline. .. Otherwise, if the current pipeline is the last pipeline in the organization, go to [Step 4](#step4) using the default pipeline (bypassing its condition, if any). .. Otherwise, repeat [Step 3.a](#step3a) using the next pipeline. . [[step4]]Route the query through the pipeline. > **Notes** > > * Unless a specific query pipeline is enforced (see [Step 1](#step1) and [Step 2](#step2)), pipelines with conditions are evaluated sequentially until a condition is satisfied (see [Step 3](#step3)). > The order of evaluation of pipelines is based on the `position` attribute, which is automatically populated when a pipeline is created, and can't be changed afterward. > > In essence, this means that pipelines with conditions are typically evaluated from oldest to newest. > This is slightly counter-intuitive, as pipelines are displayed in alphabetical order in the [Coveo Administration Console](https://docs.coveo.com/en/183/). > You can use the [List query pipelines](https://platform.cloud.coveo.com/docs?urls.primaryName=Search%20API#/Pipelines%20V1/List%20query%20pipelines) Search API operation to retrieve the actual `position` value of each pipeline in a Coveo organization. > > * It's possible for the default query pipeline to have a condition. > When this is the case, the default pipeline may be evaluated just like any other pipeline with a condition (see [Step 3](#step3)). > However, if the query doesn't satisfy the condition of any of the evaluated pipelines, it will ultimately be routed through the default pipeline, bypassing its condition. ## Specify which pipeline a query uses You can use the `pipeline` [query parameter](https://docs.coveo.com/en/13#tag/Search-V2/operation/searchUsingGet-pipeline) to specify which pipeline a query will use: * Its value is the `name` of the pipeline. * When no value is specified, a default pipeline is used. **Example** The following query will use the pipeline `mypipeline`: ```http GET /rest/search?q=@uri&pipeline=mypipeline HTTP/1.1 ``` Because no value is specified for the `pipeline` parameter in the following query, the default pipeline is used: ```http GET /rest/search?q=@uri HTTP/1.1 ```