You could check your config for an environment variable and change the name of the index that's searched depending on what environment you're in.
On my SearchPlus integration the index name is set as a data attribute on the search component, so it's possible to vary the index based on the environment:
{% set indexName = 'myindex_test' %}
{% if craft.config.craftEnv == 'production' %}
{% set indexName = 'myindex_live' %}
{% endif %}
<div class="searchplus" data-index-name="{{ indexName }}">
...
</div>
The search JavaScript reads in the data attributes on initialisation and sets up the Algolia index based on the value of data-index-name
.
Note: I'm using this with Craft 2. I understand that you can access config values in Craft 3 via craft.app.config.general.<value>
.