# Mastodon full-text search

Tags: linux debian elasticsearch mastodon

Reading time: 2 minutes

Description: A short writeup on the elasticsearch setup for full-text search in a self-hosted mastodon instance on debian






# Setting up Elasticsearch

1
2
3
4
apt install openjdk-17-jre-headless
wget -O /usr/share/keyrings/elasticsearch.asc https://artifacts.elastic.co/GPG-KEY-elasticsearch
echo "deb [signed-by=/usr/share/keyrings/elasticsearch.asc] https://artifacts.elastic.co/packages/7.x/apt stable main" > /etc/apt/sources.list.d/elastic-7.x.list
apt update && apt install elasticsearch

## Limiting the jvm heap size

1
2
-Xms4g
-Xmx4g

## Security

1
2
xpack.security.enabled: true
discovery.type: single-node

## Starting the daemon

1
2
systemctl daemon-reload
systemctl enable --now elasticsearch

## User and Role setup

1
/usr/share/elasticsearch/bin/elasticsearch-setup-passwords auto
1
2
3
4
5
6
7
8
9
curl -X POST -u elastic:yourelasticuserpasswordfromthecommandabove "localhost:9200/_security/role/mastodon_full_access?pretty" -H 'Content-Type: application/json' -d'
{
  "cluster": ["monitor"],
  "indices": [{
    "names": ["*"],
    "privileges": ["read", "monitor", "write", "manage"]
  }]
}
'
1
2
3
4
5
6
curl -X POST -u elastic:yourelasticuserpasswordfromthecommandabove "localhost:9200/_security/user/mastodon?pretty" -H 'Content-Type: application/json' -d'
{
  "password" : "anewsupersafepasswordfortheuser",
  "roles" : ["mastodon_full_access"]
}
'

# Configuring Mastodon

1
2
3
4
5
6
ES_ENABLED=true
ES_HOST=localhost
ES_PORT=9200
ES_PRESET=single_node_cluster
ES_USER=mastodon
ES_PASS=anewsupersafepasswordfortheuser
1
2
systemctl restart mastodon-sidekiq
systemctl reload mastodon-web

# Create indices and start indexing

1
RAILS_ENV=production bin/tootctl search deploy