Basic queries
To retrieve results from Algolia, use the Search index method. Querying Algolia involves:- Choosing the index to query against
- Sending the query string
- Adding optional parameters
Algolia recommends querying directly from the user’s browser, mobile device, or client to ensure optimal performance by reducing latency (and benefiting from offloading your servers).
JavaScript
Empty queries
Sometimes, you might not need to pass in a textual query. It’s possible to retrieve results from Algolia by specifying an index and other optional parameters (most likely, a filter). In this way, it’s possible to use Algolia beyond a standard “search results” experience. For example, one common use case is to use filtering capabilities to generate category landing pages.Browsing your index
Algolia allows you to fetch all records in an index using thebrowse
method. If you need to retrieve the full contents of your index (for backup, SEO purposes or for running a script on it), use the browse
method instead of search
, as search
is optimized for speed. Results are returned ranked by attributes and custom ranking. Additionally, browse
supports most search parameters, meaning you can easily apply filters to retrieve a subset of results.
Multiple indices / multiple queries
Multiple indices are used when you have different kinds of data (movies + actors), or you need to display results with different rankings. You can do this by using the same query / response logic, one for each index or query.Response format
If a query is successful, your request will generate a JSON response in return. This response contains both the matching results (hits) as well as other information useful for building a full-fledged search experience (for example: facets, highlighting, hits count, paging, and more). To learn more, see Understand the API responseHighlighting and snippeting
Highlighting is an important tool to demonstrate to searchers why a result matched their query by providing different styling to all matched query words. By default, highlighting is enabled on all searchable attributes. Snippets only return a portion of the matched attribute: the matched words and some words around them. Unlike highlighting, snippeting must be proactively enabled for each attribute you wish to snippet, although you can set the value*
to snippet all attributes.