Algolia:initialize not working (rails aborted - don't know how to build task)


first of all, this is a copy of my post into official algolia-discourse. As told by Discourse-Support, I can now post it here, therefore this is a copy-message.

I would like to setup our discourse with algolia, but it is not working like described on GitHub. I have newest version: 3.1.0.beta1.

To make first init, I open my discourse-docker with

./launcher enter app

After that, I tried different commands (bundle exec rails or only rails, also rake), but all results into:

root@rbx-communtity-service-app:/var/www/discourse# LOAD_PLUGINS=1 rails algolia:initialize
rails aborted!
Don’t know how to build task ‘algolia:initialize’ (See the list of available tasks with rails --tasks)
Did you mean? algolia:reindex

When I run just algolia:reindex, i get the following:

root@rbx-communtity-service-app:/var/www/discourse# LOAD_PLUGINS=1 rake algolia:reindex
Clearing users from Algolia
Pushing users to Algolia
Successfully pushed xxx users to Algolia
Clearing tags from Algolia
Pushing tags to Algolia
Successfully pushed xxx tags to Algolia
Clearing posts from Algolia
Pushing posts to Algolia
rake aborted!
NoMethodError: undefined method `id' for nil:NilClass
/var/www/discourse/plugins/discourse-algolia/lib/discourse_algolia/post_indexer.rb:66:in `to_object'
/var/www/discourse/plugins/discourse-algolia/lib/discourse_algolia/indexer.rb:23:in `block in process!'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord- `each'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord- `block in find_each'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord- `block in find_in_batches'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord- `block in in_batches'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord- `loop'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord- `in_batches'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord- `find_in_batches'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord- `find_each'
/var/www/discourse/plugins/discourse-algolia/lib/discourse_algolia/indexer.rb:21:in `process!'
/var/www/discourse/plugins/discourse-algolia/lib/tasks/discourse_algolia.rake:36:in `block in algolia_reindex'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord- `block in in_batches'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord- `loop'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord- `in_batches'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord- `in_batches'
/var/www/discourse/plugins/discourse-algolia/lib/tasks/discourse_algolia.rake:33:in `algolia_reindex'
/var/www/discourse/plugins/discourse-algolia/lib/tasks/discourse_algolia.rake:7:in `block in <main>'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.4.1/lib/bundler/cli/exec.rb:58:in `load'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.4.1/lib/bundler/cli/exec.rb:58:in `kernel_load'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.4.1/lib/bundler/cli/exec.rb:23:in `run'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.4.1/lib/bundler/cli.rb:491:in `exec'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.4.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.4.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.4.1/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.4.1/lib/bundler/cli.rb:34:in `dispatch'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.4.1/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.4.1/lib/bundler/cli.rb:28:in `start'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.4.1/exe/bundle:45:in `block in <top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.4.1/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.4.1/exe/bundle:33:in `<top (required)>'
/usr/local/bin/bundle:25:in `load'
/usr/local/bin/bundle:25:in `<main>'
Tasks: TOP => algolia:reindex
(See full trace by running task with --trace)

Any idea whats the issue here?

Thanks in advance!

I have installed this on my test site to give it a run-through and I also see a similar thing. Let me see what I can find out. :+1:


Have you set the algolia_discourse_username site setting by any chances?


It is set to “system”

1 Like

algolia:initialize does not exist any more. See FEATURE: Update to latest algolia gem (#33) · discourse/discourse-algolia@9a1f08f · GitHub

The needs an update.


README updated :+1:


The issue regarding reindex is still existent. I made a complete upgrade of discourse, including algolia. Also, I could not yet found a code-change inside algolia-plugin. Are there any plans on working on this?

Right now, only readme is changed, but function is still not working like initially written by me.

If needed, I can send you fresh logs from console.


There was a bug fix earlier today for an issue with reindexing and topic counts:

On the off-chance, could this have solved your issue too?

Unfortunately no :frowning: This fix is already inside my discourse-version. Same issue as before.

Pushing posts to Algolia
rake aborted!
NoMethodError: undefined method `id’ for nil:NilClass


/var/www/discourse/plugins/discourse-algolia/lib/discourse_algolia/post_indexer.rb:66:in to_object' /var/www/discourse/plugins/discourse-algolia/lib/discourse_algolia/indexer.rb:23:in block in process!’
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord- each' /var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord- block in find_each’
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord- block in find_in_batches' /var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord- block in in_batches’
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord- loop' /var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord- in_batches’
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord- find_in_batches' /var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord- find_each’

1 Like

I was over optimistically hoping for some ‘magically fixed’ :slightly_frowning_face:

I’ve given it another go on my test site and I also hit the same issue again. However, I have managed to find out some more information. :partying_face: Apparently we’re both experiencing an issue where we have at least one orphaned post that lacks a topic id, which is throwing off the rake task. The advice is to track those down and delete them, and then the rake reindex can run smoothly.

I haven’t put this into practice for finding the problem post(s) yet so haven’t got a step-by-step, but thought I’d give you a heads up in case this is something you’d like to explore before I get to it. :+1:


I am debugging it right now.

Did you change default algolia_discourse_username site setting? If yes, please ensure that you are using non-admin user.


I have given this yet another go… :slight_smile: And I can confirm that removing ‘system’ from the algolia discourse username setting and running rake algolia:reindex with a dummy user instead worked without error. :+1:

I shamefully did not spot the bit in the instructions about:

It is recommended that you create a dummy separate user who can only see content you consider to be public, and change this value to their username.

And only matched my settings per this instruction:

Once all of the settings are turned on and populated, the plugin configuration should look like this:

Personally, (and I may be biased :slight_smile:) I think we could maybe make those instructions a little clearer. :slight_smile: I would advocate for a section ‘Create your algolia discourse user’ as part of the configuration flow.


Actually, in latest PR I removed that option as it is possibly dangerous. When a user with admin access is used, it can show restricted posts in search.


That’s an even better idea. :slight_smile:


thanks, now it is working :slight_smile: My three indices are created and sent to algolia!