Closed joscha closed 4 years ago
This was indeed a very cryptic error and I think the error should tell the user to go to their Algolia dashboard and create an index with an updated name, as joscha said.
Happy to change this PR in any way that removes the cryptic error. You say Algolia creates the index automatically, but it guaranteed did not for me. I folllowed https://www.gatsbyjs.org/docs/adding-search-with-algolia/. If you hint me towards where to get the main index from that you are talking about I am happy to make changes to the pull request. Please keep in mind that you need a fresh Algolia account (without any indices) to reproduce it.
The Algolia API does create the index if you add any objects (or set a settings) to it, no doubt about that. I've tested locally with my application and an index that doesn't exist. I'm able to push objects to it without errors.
The plugin doesn't work when the index doesn't exist (the plugin, not Algolia). The function linked above select on which index the plugin have to push data. By default we use a tempIndex
to avoid to update the "main" index (i.e. index
in the code above) used by the application. If the index already exists we use the temp one but if it doesn't we don't return an instance of the index. The fix is to return index
in case it doesn't exist yet. That way it will be created on we push objects to it.
Actually two issues exist: one with partial update enabled and the index doesn't exist, another one when partial update is not enabled and the index doesn't exist. The first issue is because we call browseAll
on an index that doesn't exist. This call throws an error but not the one linked in this issue. The second issue is the one described above.
Thanks for this PR, but it's indeed solved by Samuel's PR as well
Currently, the error looks like this:
I found this issue after myself and a bit of googling showed I am not the only one: https://stackoverflow.com/questions/61521867/why-did-i-fail-to-index-to-algolia/61523372#61523372