Optimize InstantSearch iOS search requests
Each keystroke sent to an Algolia index or multi-index counts as one search request. To reduce the number of requests sent to Algolia, and potentially reduce billing, you can “debounce searches”.
What influences search request usage
Your usage depends on factors that influence the volume of search requests, such as:
- Where do you plan to implement Algolia? If you implement both mobile and desktop apps, your search request usage will be more than if you just had a desktop app.
- Will you just capture searches or also capture other elements? Expect more search request usage if you also use Algolia to capture other elements such as navigation on category pages, discovery solutions, and other implementations like marketing landing pages and shared widgets.
How to optimize search request usage
You can make changes to both your frontend and backend implementations to ensure your search request usage is as intended.
Optimize search requests on your frontend implementation
To find out how to optimize the number of search requests, use the browser’s developer tools console to inspect Algolia API calls.
Check per keystroke
Type in the search bar and see how many API calls are sent to Algolia at each keystroke.
By default, there is one request for each keystroke and index.
If you use federated search, you have separate requests for each queried index. Compare the number of search requests for three elements - the API calls, the number of keystrokes, and the results.
- If you have more requests than your displayed indices, they could be duplicating queries to the same index or querying indices that aren’t displayed.
- If you have a non-optimized multi-index search request, you are already successfully using the multi-query endpoint (federated search uses multiple indices).
- If you don’t group the requests into one network request, all requests are on separate lines and billed separately.
- If you have an optimized multi-index search request and you have five different requests, the multi-query endpoint groups all five different requests to different indices.
Check per facet click
If you have facets on the search engine results page, check how many search requests are sent when applying facets. There should only be one.
Check on page load
- Clear your browser’s cache and reload the page. Were any queries sent to Algolia? If yes, check to see if any Algolia results are being displayed on the page by default. It could be that a query is sent to populate the page’s contents, like on category pages.
- If Algolia-delivered results aren’t visible on the page, this could be a redundant query. You can use your discretion to remove the query.
Check if you are using single or multi-query endpoint
How you query Algolia is important and can make a big difference to your billing. Each line in your browser developer tool’s Network tab is called a “network request”.
A network request that starts with “query” means only one request was sent to one index.
A network request starting with “queries” means that two or more queries are grouped in a single network request, and it’s either used to search through multiple indices or it’s searching through one index but needs to make multiple queries. An example of a search through one index with multiple queries is when using dynamic facets which could cause an extra search request.
You need to optimize if you have a multi-index search implementation and there are few calls to the multi-query endpoint. Algolia has API clients to help you optimize the usage of multi-query endpoints, including an API for InstantSearch and for frontend libraries like Magento.
Check for expected signs of usage
- Check for linear growth in the number of queries over time. Study the graph in the Monitoring > Usage section in your dashboard.
- Check for linear growth in Analytics for searches in comparison to the number of users. A high number of searches per user can mean:
- You have a backend implementation.
- You have a low number of users.
- You have a bug that is sending too many queries per keystroke.
- Your search is used more extensively than initially scoped. For example, after an initial scope to power your search, has Algolia now been implemented on the category pages or has it been extended to a new country? This could result in an increase in search requests.
- Check for abnormal spikes in search requests. For example, is there an increase during holiday or sale seasons?
- Compare search queries and the average number of visitors. This comparison depends on your use case and search experience. For example, if you use Algolia to browse and search, you will have more queries per user. And the number of as-you-type queries depends on how prominently the search bar is displayed.
Check if you are making extended use of Algolia
Check if Algolia is used across multiple domains beyond the initial scope.
Check Analytics on your dashboard to see the top searches
- Check if a high number of searches are labeled as “empty search”. This means that a majority of the usage is going towards browsing the content page.
- Check the Searches tab to see if the filters on the “empty search” queries have a category-based filter. This implies that Algolia is used extensively for filters and category pages. If this wasn’t scoped for initially, it could explain a high search request usage.
Check for bots crawling your website
Google bots could cause an increase in search queries.
Optimize search requests on your backend and native mobile implementations
Depending on your implementation, you may need to use your internal tools to investigate.
Check the usage of each search endpoint by looking at the incoming API operations on the Algolia dashboard’s Monitoring > Operations > API Calls section. If you are using a multi-index search and few calls are made to the multi-query endpoint, there is room for optimization.