7dbbd3e175f37e60f9b4a347aab5c8b820c23bc8
[akkoma] / docs / configuration / search.md
1 # Configuring search
2
3 {! backend/administration/CLI_tasks/general_cli_task_info.include !}
4
5 ## Built-in search
6
7 To use built-in search that has no external dependencies, set the search module to `Pleroma.Activity`:
8
9 > config :pleroma, Pleroma.Search, module: Pleroma.Search.DatabaseSearch
10
11 While it has no external dependencies, it has problems with performance and relevancy.
12
13 ## Meilisearch
14
15 Note that it's quite a bit more memory hungry than PostgreSQL (around 4-5G for ~1.2 million
16 posts while idle and up to 7G while indexing initially). The disk usage for this additional index is also
17 around 4 gigabytes. Like [RUM](./cheatsheet.md#rum-indexing-for-full-text-search) indexes, it offers considerably
18 higher performance and ordering by timestamp in a reasonable amount of time.
19 Additionally, the search results seem to be more accurate.
20
21 Due to high memory usage, it may be best to set it up on a different machine, if running pleroma on a low-resource
22 computer, and use private key authentication to secure the remote search instance.
23
24 To use [meilisearch](https://www.meilisearch.com/), set the search module to `Pleroma.Search.Meilisearch`:
25
26 > config :pleroma, Pleroma.Search, module: Pleroma.Search.Meilisearch
27
28 You then need to set the address of the meilisearch instance, and optionally the private key for authentication.
29
30 > config :pleroma, Pleroma.Search.Meilisearch,
31 > url: "http://127.0.0.1:7700/",
32 > private_key: "private key"
33
34 Information about setting up meilisearch can be found in the
35 [official documentation](https://docs.meilisearch.com/learn/getting_started/installation.html).
36 You probably want to start it with `MEILI_NO_ANALYTICS=true` and `MEILI_NO_CENTRY=true` environment variables,
37 to disable analytics.
38
39 ### Private key authentication (optional)
40
41 To set the private key, use the `MEILI_MASTER_KEY` environment variable when starting. After setting the _master key_,
42 you have to get the _private key_, which is actually used for authentication.
43
44 === "OTP"
45 ```sh
46 ./bin/pleroma_ctl search.meilisearch show-private-key <your master key here>
47 ```
48
49 === "From Source"
50 ```sh
51 mix pleroma.search.meilisearch show-private-key <your master key here>
52 ```
53
54 This is the key you actually put into your configuration file.
55
56 ### Initial indexing
57
58 After setting up the configuration, you'll want to index all of your already existsing posts. Only public posts are indexed. You'll only
59 have to do it one time, but it might take a while, depending on the amount of posts your instance has seen. This is also a fairly RAM
60 consuming process for `meilisearch`, and it will take a lot of RAM when running if you have a lot of posts (seems to be around 5G for ~1.2
61 million posts while idle and up to 7G while indexing initially, but your experience may be different).
62
63 The sequence of actions is as follows:
64
65 1. First, change the configuration to use `Pleroma.Search.Meilisearch` as the search backend
66 2. Restart your instance, at this point it can be used while the search indexing is running, though search won't return anything
67 3. Start the initial indexing process (as described below with `index`),
68 and wait until the task says it sent everything from the database to index
69 4. Wait until everything is actually indexed (by checking with `stats` as described below),
70 at this point you don't have to do anything, just wait a while.
71
72 To start the initial indexing, run the `index` command:
73
74 === "OTP"
75 ```sh
76 ./bin/pleroma_ctl search.meilisearch index
77 ```
78
79 === "From Source"
80 ```sh
81 mix pleroma.search.meilisearch index
82 ```
83
84 This will show you the total amount of posts to index, and then show you the amount of posts indexed currently, until the numbers eventually
85 become the same. The posts are indexed in big batches and meilisearch will take some time to actually index them, even after you have
86 inserted all the posts into it. Depending on the amount of posts, this may be as long as several hours. To get information about the status
87 of indexing and how many posts have actually been indexed, use the `stats` command:
88
89 === "OTP"
90 ```sh
91 ./bin/pleroma_ctl search.meilisearch stats
92 ```
93
94 === "From Source"
95 ```sh
96 mix pleroma.search.meilisearch stats
97 ```
98
99 ### Clearing the index
100
101 In case you need to clear the index (for example, to re-index from scratch, if that needs to happen for some reason), you can
102 use the `clear` command:
103
104 === "OTP"
105 ```sh
106 ./bin/pleroma_ctl search.meilisearch clear
107 ```
108
109 === "From Source"
110 ```sh
111 mix pleroma.search.meilisearch clear
112 ```
113
114 This will clear **all** the posts from the search index. Note, that deleted posts are also removed from index by the instance itself, so
115 there is no need to actually clear the whole index, unless you want **all** of it gone. That said, the index does not hold any information
116 that cannot be re-created from the database, it should also generally be a lot smaller than the size of your database. Still, the size
117 depends on the amount of text in posts.