Elasticsearch server setup
Elasticsearch allows you to search large volumes of data quickly, in near real-time, by creating and managing an index of post data. The indexing process can be managed from the System Console after setting up and connecting an Elasticsearch server. The post index is stored on the Elasticsearch server and updated constantly after new posts are made. In order to index existing posts, a bulk index of the entire post database must be generated.
Deploying Elasticsearch includes the following two steps: setting up Elasticsearch, and configuring Mattermost.
Set up Elasticsearch
We highly recommend that you set up Elasticsearch server on a dedicated machine separate from the Mattermost Server.
- Download and install the latest release of Elasticsearch v9 or Elasticsearch v8. See the Elasticsearch documentation for installation details.
- Set up Elasticsearch with
systemdby running the following commands:
sudo /bin/systemctl daemon-reloadsudo /bin/systemctl enable elasticsearch.servicesudo systemctl start elasticsearch.service
- Confirm Elasticsearch is working on the server by running the following command:
curl localhost:9200
- Get your network interface name by running the following command:
ip addr
- Edit the Elasticsearch configuration file in
viby running the following command:
vi /etc/elasticsearch/elasticsearch.yml
- In this file, replace the
network.hostvalue of_eth0_with your network interface name, and save your changes. - Ensure you set
action.destructive_requires_nametofalseinelasticsearch.ymlto allow for wildcard operations to work. - Restart Elasticsearch by running the following commands:
sudo systemctl stop elasticsearchsudo systemctl start elasticsearch
- Confirm the ports are listenings by running the following command:
netstat -plntYou should see the following ports, including the ones listening on ports 9200 and 9300. Confirm these are listening on your server's IP address.
- Create an Elasticsearch directory and give it the proper permissions.
- Install the icu-analyzer plugin to the
/usr/share/elasticsearch/pluginsdirectory by running the following command:
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-icuRestart Elasticsearch on each node to load the newly installed plugin before verifying it;
_cat/pluginsonly reports active plugins, so a restart is required first. For production clusters, restart nodes one at a time (rolling restart) rather than all at once. Confirm the plugin is installed and active on every node before continuing. Replace<your-elasticsearch-host>and<password>, and update the CA path if needed:curl --silent --show-error --fail-with-body --cacert /etc/elasticsearch/certs/http_ca.crt --user 'elastic:<password>' 'https://<your-elasticsearch-host>:9200/_cat/plugins?v&h=name,component,version&s=name,component'Running this command should show
analysis-icuonce per node in the cluster. If theanalysis-iculine is missing for any node, the plugin is not installed there. Use plain HTTP without credentials only for a cluster where Elasticsearch security has been explicitly disabled.(Optional) CJK language analyzer plugins: To improve search for Korean, Japanese, or Chinese content, install one or more of the following language-specific analyzer plugins:
analysis-nori(Korean),analysis-kuromoji(Japanese), andanalysis-smartcn(Chinese).sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-norisudo /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-kuromojisudo /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-smartcnAfter installing the CJK plugins, restart Elasticsearch to load them:
sudo systemctl restart elasticsearchThen enable the EnableCJKAnalyzers configuration setting. See Enabling Chinese, Japanese, and Korean Search for additional CJK search configuration options.
Important
If you enable CJK analyzers on a server with existing indexed content, you must purge and rebuild the search index in System Console > Environment > Elasticsearch for the CJK analyzers to take effect on existing posts.
- Test the connection from Mattermost to Elasticsearch by running the following command:
curl 172.31.80.220:9200
Configure Mattermost
Follow these steps to configure Mattermost to use your Elasticsearch server and to generate the post index:
- Go to System Console > Environment > Elasticsearch.
- Set Enable Elasticsearch Indexing to
trueto enable the other the settings on the page. Once the configuration is saved, new posts made to the database are automatically indexed on the Elasticsearch server. - Ensure Backend type is set to
elasticsearch.
- (Optional) Enter Server Username used to access the enterprise search server.
- (Optional) Enter Server Password associated with the username.
- Set Enable Cluster Sniffing (Optional). Sniffing finds and connects to all data nodes in your cluster automatically.
- Optional CA and client certificate configuration settings are available for use with basic authentication credentials or to replace them. See the Enterprise search configuration settings documentation for details.
- Select Test Connection and then select Save. If the server connection is unsuccessful you won't be able to save the configuration or enable searching with Elasticsearch or AWS OpenSearch.
Build the post index of existing messages
Select Index Now. This process can take up to a few hours depending on the size of the post database and number of messages. The progress percentage can be seen as the index is created. To avoid downtime, set Enable Elasticsearch for search queries to false so that database search is available during the indexing process.
Enable enterprise search
Ensure bulk indexing is complete before enabling enterprise search, otherwise search results will be incomplete.
Set Enable Elasticsearch for search queries to true, and setting Enable Elasticsearch for autocomplete to true. Save your configuration updates and restart the Mattermost server.
Once the configuration is saved, new posts made to the database are automatically indexed on the Elasticsearch or AWS OpenSearch server.
Enterprise search limitations
- Elasticsearch and AWS OpenSearch use a standard selection of "stop words" to keep search results relevant. Results for the following words will not be returned: "a", "an", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it", "no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", and "with".
- Searching stop words in quotes returns more results than just the searched terms (ticket).
- By default, search results are limited to a user's team and channel membership. This is enforced by the Mattermost server. The entities are indexed in Elasticsearch or AWS OpenSearch in a way that allows Mattermost to filter them when querying, so the Mattermost server narrows down the results on every Elasticsearch or AWS OpenSearch request applying those filters. From Mattermost v11.6, admins can allow searching public channels without membership so that users can find messages in public channels they haven't joined, scoped to teams they belong to.
- User search and autocomplete served by Elasticsearch or AWS OpenSearch match on username, nickname, and first and last name only. Email addresses aren't indexed, so no user can be found by email address, including system admins. User searches served from the database continue to match on email address. For channel and team member searches, system admins always match on email address, and all other users also require Show email address to be enabled. The System Console > User Management > Users list always matches on email address, independently of that setting.