This guide is intended for general Algolia Implementations (Shopify and Magento extensions already have this built-in mechanism).
There are a couple options to exclude certain products from your search results. That being either with your out of stock products indexed or not:
1 - Out of stock products Indexed
Assuming you have an attribute that contains the inventory count, or a boolean that indicates if it's in stock or not, this can be done with a query-time filter or a conditionless rule filtering all queries to discard any out-of-stock records.
For example, with a boolean attribute (i.e: in_stock), you can create a conditionless rule that will apply on every search term. So for the records that you would like to show, you could set the boolean attribute (in_stock) value to 'true'. Then your filter on your conditionless rule could be: {"filters":"in_stock:true”}.
To do so, you can create a new rule and select "Manual Editor”:
Remove the conditions to create a conditionless rule and set the filter on the "Add Query Parameter" option on your consequences:
As the one used for this example {"filters":"in_stock:true”}:
2 - Out of stock products Not Indexed
This approach would require some development work, though it would help you to reduce your record usage for those products that you don't need on your Search results. On this case, you might need to create a logic on your end to exclude those out of stock products from your index.
To achieve this implementation you can leverage the following API Client documentation: https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/#updating-your-data