Algolia for Discourse not working (incl. logs and suggestion)

Hi guys!

Desperate I’d love to use Algolia on Discourse because I think this search engine is brilliant.

I need help, maybe someone here will know how to solve this problem… I’m targeting the wider community, so I hope that this will increase the chances.

When I installed the plugin (default configuration, Discourse in Docker) and completed the API keys, and then used the indexing command, there was a problem. Support provided me with such information:

The issue is still related to the fact that the settings didn’t persist to your script. You can see that by the fact that there’s no api key or app id in the logs

The SiteSetting.algolia_application_id is .

Should have been

The SiteSetting.algolia_application_id is XXXXXXXXXX.

Any idea?

1 Like

Hey there :wave:

I agree it seems something related to how those value are stored inside your discourse database.

Could you check first if your Application ID and API keys are correctly displayed in your plugin configuration?

You can check it out from the following URL:

Also, it may be worth if there’s any errors in the system logs:

Let me know if this helps!

1 Like

Of cooourseee, nothing is empty in the settings :slight_smile: In the logs nothing related to Algolia.

Looks good to me :thinking:

Did you already try to manually force re-indexing? You can do so from the console with

bundle exec algolia:reindex

(probably yes, but worth a try!)

Your command won’t work, but I used this:

LOAD_PLUGINS=1 bundle exec rails algolia:initialize

And that’s what I’m getting (please keep in mind i made some commit suggested by support, to get more details on this):

[Starting] Pushing users index settings to Algolia
The SiteSetting.algolia_application_id is .
The SiteSetting.algolia_admin_api_key is .
rails aborted!
Algolia::AlgoliaProtocolError: Cannot reach any host: getaddrinfo: Name or service not known (, getaddrinfo: Name or service not known (, getaddrinfo: Name or service not known (, getaddrinfo: Name or service not known (
/var/www/discourse/plugins/discourse-algolia/gems/2.5.1/gems/algoliasearch-1.18.0/lib/algolia/client.rb:365:in `request'
/var/www/discourse/plugins/discourse-algolia/gems/2.5.1/gems/algoliasearch-1.18.0/lib/algolia/client.rb:377:in `put'
/var/www/discourse/plugins/discourse-algolia/gems/2.5.1/gems/algoliasearch-1.18.0/lib/algolia/index.rb:483:in `set_settings'
/var/www/discourse/plugins/discourse-algolia/lib/tasks/discourse_algolia.rake:39:in `algolia_configure_users'
/var/www/discourse/plugins/discourse-algolia/lib/tasks/discourse_algolia.rake:9:in `block in <top (required)>'
/var/www/discourse/plugins/discourse-algolia/lib/tasks/discourse_algolia.rake:3:in `block in <top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/railties-5.2.0/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/railties-5.2.0/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/railties-5.2.0/lib/rails/command.rb:48:in `invoke'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/railties-5.2.0/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:16:in `require'
bin/rails:16:in `<main>'

Ok, could you try to launch your rails console and check that SiteSetting value?

bundle exec rails console

If the values are there then I guess the plugin may be incompatible with your discourse version, on which version are you currently on?

Ugh, I tried this, but smth went wrong (dunno why)…

/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/pg-1.1.0/lib/pg.rb:56:in `initialize’: FATAL: Peer authentication failed for user “discourse” (PG::ConnectionBad)

I’m using the newest one (beta obviously, default Discourse installation without any customized confs).

Nevermind, I used rails c and it seems to work.

[1] pry(main)> SiteSetting.algolia_application_id XXXXXXXXXX
SyntaxError: unexpected tCONSTANT, expecting end-of-input
…golia_application_id XXXXXXXXXX
… ^~~~~~~~~

I think the error that you reported may explain why the rake task is not able to fetch the correct values from the database! Maybe you’re using a different user for the production environment, try:

RAILS_ENV=production bundle exec rails console

If this works and you correctly display your settings then you can try to run again:

RAILS_ENV=production LOAD_PLUGINS=1 bundle exec rails algolia:initialize

Even with this command I got this error:

/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/pg-1.1.0/lib/pg.rb:56:in `initialize’: FATAL: Peer authentication failed for user “discourse” (PG::ConnectionBad)

rails c seems to be just OK, isn’t it?

Did you try also LOAD_PLUGINS=1 rails algolia:initialize (without the bundle exec?)

1 Like

Wow, it worked :slight_smile: Now even search results appear immediately :3

So, instead of

LOAD_PLUGINS=1 bundle exec rails algolia:initialize

which is suggested on Github, i had to use this:

LOAD_PLUGINS=1 rails algolia:initialize

Thanks for your help! I’ll send pull request on Github and inform about this on their forum :wink:


Cool, glad to hear it worked! :tada: