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

# Federated search with multifeed compositions

> Build a federated search experience by combining multiple feeds in a single composition.

export const Feed = () => <Tooltip tip="Group of items used in a composition. Sources can be search results, recommendations, or external data." href="/doc/guides/compositions/multifeed-compositions" cta="Multifeed compositions">
    feed
  </Tooltip>;

Multifeed compositions let you return several independently ranked result feeds from a single API request.
They're the foundation for federated search, displaying results from different product categories, brands, content types, or geographies in a unified result set.

This guide walks through assembling a multifeed composition for a football-themed product listing page (PLP), starting from a single index and then extending to multiple indices and Smart Groups.
For the underlying concept, see [Multifeed compositions](/doc/guides/compositions/multifeed-compositions).

Before you begin, review the [Composition API requirements](/doc/guides/compositions#before-you-begin-using-the-compositions-api).

<Note>
  **Use case:** "I want to build a PLP that surfaces new arrivals in carousels by product tier: Tier A for top clubs, Tier B for mid-tier, and Tier C for the rest. This replaces static manual processes site-wide."
</Note>

This example builds a federated PLP with carousels for brands, latest items, and trending items.

## Entry points

This composition supports two entry points: a search query for `football` on the browse PLP, and the category page route `/football`.

<Tabs>
  <Tab title="Category page">
    ```
    {
      "params": {
        "query": "",
        "filters": "categoryPageId:football"
      }
    }
    ```
  </Tab>

  <Tab title="Browse query">
    ```
    {
      "params": {
        "query": "football"
      }
    }
    ```
  </Tab>
</Tabs>

## Configure with the API

Create the composition with the [Update and insert composition](/doc/rest-api/composition/put-composition) endpoint, then apply the `behavior` defined below.
To scope the behavior to a specific search query, category, or context, send the same `behavior` inside a composition rule's `consequence.behavior` with the [Update and insert composition rule](/doc/rest-api/composition/put-composition-rule) endpoint.

<Tabs>
  <Tab title="Single index">
    <Steps>
      <Step title="Add the brand feed">
        ```json JSON icon=braces expandable theme={"system"}
        {
          "behavior": {
            "multifeed": {
              "feeds": {
                "football-brands": {
                  "injection": {
                    "main": {
                      "source": {
                        "search": {
                          "index": "products",
                          "params": {
                            "filters": "category:football"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
        ```
      </Step>

      <Step title="Add the trending feed">
        ```json JSON icon=braces expandable highlight={19-34,36-39} theme={"system"}
        {
          "behavior": {
            "multifeed": {
              "feeds": {
                "football-brands": {
                  "injection": {
                    "main": {
                      "source": {
                        "search": {
                          "index": "products",
                          "params": {
                            "filters": "category:football"
                          }
                        }
                      }
                    }
                  }
                },
                "football-trending": {
                  "injection": {
                    "main": {
                      "source": {
                        "recommend": {
                          "indexName": "products",
                          "model": "trending-items",
                          "threshold": 3,
                          "queryParameters": {
                            "filters": "category:football"
                          }
                        }
                      }
                    }
                  }
                }
              },
              "feedsOrder": [
                "football-brands",
                "football-trending"
              ]
            }
          }
        }
        ```
      </Step>

      <Step title="Add the latest-in-football feed">
        ```json JSON icon=braces expandable highlight={19-32,52} theme={"system"}
        {
          "behavior": {
            "multifeed": {
              "feeds": {
                "football-brands": {
                  "injection": {
                    "main": {
                      "source": {
                        "search": {
                          "index": "products",
                          "params": {
                            "filters": "category:football"
                          }
                        }
                      }
                    }
                  }
                },
                "football-latest": {
                  "injection": {
                    "main": {
                      "source": {
                        "search": {
                          "index": "products",
                          "params": {
                            "filters": "category:football AND new:true"
                          }
                        }
                      }
                    }
                  }
                },
                "football-trending": {
                  "injection": {
                    "main": {
                      "source": {
                        "recommend": {
                          "indexName": "products",
                          "model": "trending-items",
                          "threshold": 3,
                          "queryParameters": {
                            "filters": "category:football"
                          }
                        }
                      }
                    }
                  }
                }
              },
              "feedsOrder": [
                "football-brands",
                "football-latest",
                "football-trending"
              ]
            }
          }
        }
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="Multiple indices">
    <Steps>
      <Step title="Add the brand feed on the products index">
        ```json JSON icon=braces expandable theme={"system"}
        {
          "behavior": {
            "multifeed": {
              "feeds": {
                "football-brands": {
                  "injection": {
                    "main": {
                      "source": {
                        "search": {
                          "index": "product-brands",
                          "params": {
                            "filters": "category:football"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
        ```
      </Step>

      <Step title="Add the popular feed from the UK product index">
        ```json JSON icon=braces expandable highlight={19-32,34-37} theme={"system"}
        {
          "behavior": {
            "multifeed": {
              "feeds": {
                "football-brands": {
                  "injection": {
                    "main": {
                      "source": {
                        "search": {
                          "index": "product-brands",
                          "params": {
                            "filters": "category:football"
                          }
                        }
                      }
                    }
                  }
                },
                "football-popular-uk": {
                  "injection": {
                    "main": {
                      "source": {
                        "search": {
                          "index": "uk-products",
                          "params": {
                            "filters": "category:football"
                          }
                        }
                      }
                    }
                  }
                }
              },
              "feedsOrder": [
                "football-brands",
                "football-popular-uk"
              ]
            }
          }
        }
        ```
      </Step>

      <Step title="Add the popular feed from the French product index">
        ```json JSON icon=braces expandable highlight={33-46,51} theme={"system"}
        {
          "behavior": {
            "multifeed": {
              "feeds": {
                "football-brands": {
                  "injection": {
                    "main": {
                      "source": {
                        "search": {
                          "index": "product-brands",
                          "params": {
                            "filters": "category:football"
                          }
                        }
                      }
                    }
                  }
                },
                "football-popular-uk": {
                  "injection": {
                    "main": {
                      "source": {
                        "search": {
                          "index": "uk-products",
                          "params": {
                            "filters": "category:football"
                          }
                        }
                      }
                    }
                  }
                },
                "football-popular-fr": {
                  "injection": {
                    "main": {
                      "source": {
                        "search": {
                          "index": "fr-products",
                          "params": {
                            "filters": "category:football"
                          }
                        }
                      }
                    }
                  }
                }
              },
              "feedsOrder": [
                "football-brands",
                "football-popular-uk",
                "football-popular-fr"
              ]
            }
          }
        }
        ```
      </Step>
    </Steps>
  </Tab>
</Tabs>

## Enhance your feeds

### Add a feed for trending items

Add a Recommend <Feed /> to power a trending-items carousel.
This example pulls trending items from the `uk-products` index, filtered to the football category.

```json JSON icon=braces expandable theme={"system"}
{
  "behavior": {
    "multifeed": {
      "feeds": {
        "football-brands": {
          "injection": {
            "main": {
              "source": {
                "search": {
                  "index": "product-brands",
                  "params": {
                    "filters": "category:football"
                  }
                }
              }
            }
          }
        },
        "football-trending-uk": {
          "injection": {
            "main": {
              "source": {
                "recommend": {
                  "indexName": "uk-products",
                  "model": "trending-items",
                  "threshold": 3,
                  "queryParameters": {
                    "filters": "category:football"
                  }
                }
              }
            }
          }
        }
      },
      "feedsOrder": [
        "football-brands",
        "football-trending-uk"
      ]
    }
  }
}
```

### Inject an external source Smart Group

Inject an external source Smart Group into one of your feeds to surface sponsored items selected at query time by your retail-media platform or bidding system.
The object IDs are passed in the request body when querying the composition (see [External source groups](/doc/guides/compositions/smart-groups/external-source-groups)).

```json JSON icon=braces expandable theme={"system"}
{
  "behavior": {
    "multifeed": {
      "feeds": {
        "football-brands": {
          "injection": {
            "main": {
              "source": {
                "search": {
                  "index": "product-brands",
                  "params": {
                    "filters": "category:football"
                  }
                }
              }
            },
            "injectedItems": [
              {
                "key": "sponsored-football",
                "source": {
                  "external": {
                    "index": "products",
                    "ordering": "userDefined"
                  }
                },
                "position": 0,
                "length": 3
              }
            ]
          }
        }
      },
      "feedsOrder": [
        "football-brands"
      ]
    }
  }
}
```

### Hide feeds

You can hide or reorder feeds with the `feedsOrder` field.
Set it on the composition itself, on a composition rule, or pass it at query time.
Omitting a feed from `feedsOrder` hides it for that scope. Reordering changes the order of feeds in the response.

<Tabs>
  <Tab title="In the composition">
    Update `feedsOrder` on the composition to change the default order or hide a feed across all queries (here, `football-popular-uk` is omitted to hide it).

    ```json JSON icon=braces expandable theme={"system"}
    {
      "behavior": {
        "multifeed": {
          "feedsOrder": [
            "football-brands",
            "football-trending"
          ]
        }
      }
    }
    ```
  </Tab>

  <Tab title="In a composition rule">
    Set `feedsOrder` inside the rule's `consequence.behavior.multifeed` so it applies only when the rule's conditions match.

    ```json JSON icon=braces expandable theme={"system"}
    {
      "consequence": {
        "behavior": {
          "multifeed": {
            "feedsOrder": [
              "football-brands",
              "football-trending"
            ]
          }
        }
      }
    }
    ```
  </Tab>

  <Tab title="At query time">
    Pass `feedsOrder` in the search request body to override the composition's default for that query only.

    ```json JSON icon=braces expandable theme={"system"}
    {
      "params": {
        "query": "football"
      },
      "feedsOrder": [
        "football-brands",
        "football-trending"
      ]
    }
    ```
  </Tab>
</Tabs>

## See also

* [Multifeed compositions](/doc/guides/compositions/multifeed-compositions)
* [Smart Groups](/doc/guides/compositions/smart-groups/smart-groups)
* [External source groups](/doc/guides/compositions/smart-groups/external-source-groups)
* [Recommend-based groups](/doc/guides/compositions/smart-groups/recommend-based-groups)
* [Composition REST API reference](/doc/rest-api/composition)
