Full-text search

Mastodon supports full-text search when it ElasticSearch is available. Mastodon’s full-text search allows logged in users to find results from their own toots, their favourites, and their mentions. It deliberately does not allow searching for arbitrary strings in the entire database.

Installing ElasticSearch

ElasticSearch requires a Java runtime. If you don’t have Java already installed, do it now. Assuming you are logged in as root:

apt install openjdk-8-jre-headless

Add the official ElasticSearch repository to apt:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-6.x.list
apt update

Now you can install ElasticSearch:

apt install elasticsearch

To start ElasticSearch:

systemctl enable elasticsearch
systemctl start elasticsearch

Configuring Mastodon

Edit .env.production to add the following variables:

ES_ENABLED=true
ES_HOST=localhost
ES_PORT=9200

If you have multiple Mastodon servers on the same machine, and you are planning to use the same ElasticSearch installation for all of them, make sure that all of them have unique REDIS_NAMESPACE in their configurations, to differentiate the indices. If you need to override the prefix of the ElasticSearch index, you can set ES_PREFIX directly.

After saving the new configuration, create the index in ElasticSearch with:

RAILS_ENV=production bundle exec rake chewy:upgrade

Then restart Mastodon processes for the new configuration to take effect:

systemctl restart mastodon-sidekiq
systemctl reload mastodon-web

Now new statuses will be written to the ElasticSearch index. The last step is importing all of the old data as well. This might take a long while:

RAILS_ENV=production bundle exec rake chewy:sync

Last updated

Was this helpful?