Skip to content

Commit bc84cf4

Browse files
authored
Merge pull request #100 from wireapp/WPB-21670-docs-for-es-reindex
documentation for ES reindexing
2 parents 904cb77 + 7f418e4 commit bc84cf4

1 file changed

Lines changed: 198 additions & 0 deletions

File tree

src/how-to/administrate/elasticsearch.md

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,204 @@ This is the command to list the nodes in the cluster:
9191
ssh <ip of elasticsearch node> curl 'http://localhost:9200/_cat/nodes?v&h=id,ip,name'
9292
```
9393

94+
## How to recreate ES index
95+
96+
If you are facing issues with an existing index due to conflicting mappings or seeing this error when updating `wire-server`:
97+
98+
```
99+
400 - {"error":{"type":"illegal_argument_exception", "reason":"Mapper for [email_unvalidated] conflicts with existing mapping"}}
100+
```
101+
102+
### Using existing charts, existing index and ES native API
103+
104+
Charts for `wire-server` will be needed, specifically, subchart `elasticsearch-index`.
105+
106+
Create a new index with the new mappings by configuring a `values.yaml` file like so:
107+
108+
```
109+
elasticsearch:
110+
host: your-elasticsearch-host
111+
index: new-index-name # default/current is directory, so pick something else
112+
image:
113+
tag: 5.23.0 # minimal wire-server version this was tested with
114+
```
115+
116+
Find your current `elasticsearch-index-create` job and delete it:
117+
118+
```
119+
kubectl get pods | grep elasticsearch
120+
kubectl delete pod elasticsearch-index-create-xxxx
121+
```
122+
123+
Then helm install the elasticsearch-index charts with the previously configured `values.yaml`:
124+
125+
```
126+
helm install --upgrade elasticsearch-index charts/wire-server/charts/elasticsearch-index -f values.yaml
127+
```
128+
129+
This will create a new index ('new-index-name') in ES cluster.
130+
To verify, log onto your ES cluster machine and run:
131+
132+
```
133+
curl "localhost:9200/_cat/indices"
134+
```
135+
136+
Or `exec` into a `brig` pod, and curl it with your Elasticsearch service name from the `brig` pod.
137+
138+
Depending on your ES setup, you might need to use https and provide credentials.
139+
In the output you should see your new index there.
140+
141+
Next, configure `wire-server` values file to use both the new index and the old one (until we populate the new with old index data).
142+
143+
```
144+
brig:
145+
config:
146+
elasticsearch:
147+
index: directory # default wire-server value
148+
additionalWriteIndex: new-index-name-here
149+
```
150+
151+
Apply it:
152+
153+
```
154+
kubectl upgrade --install wire-server charts/wire-server -f values/wire-server/values.yaml -f values/wire-server/secrets.yaml
155+
```
156+
157+
Now use native reindex ES API in your ES cluster like so:
158+
159+
```
160+
curl "localhost:9200/_reindex?wait_for_completion" -H 'Content-Type: application/json' -d '{"source": {"index": "directory"}, "dest": {"index": "new-index-name-here"}}'
161+
```
162+
163+
Wait for the result. Now switch the main/additional indexes in `wire-server`.
164+
165+
```
166+
brig:
167+
config:
168+
elasticsearch:
169+
index: new-index-name-here
170+
additionalWriteIndex: directory
171+
```
172+
173+
Apply it:
174+
175+
```
176+
kubectl upgrade --install wire-server charts/wire-server -f values/wire-server/values.yaml -f values/wire-server/secrets.yaml
177+
```
178+
179+
Now log onto Team Settings and check your member list if it is correct.
180+
If it is, you can stop using `additionalWriteIndex` and delete the old one.
181+
182+
### Using modified Helm charts (and building it from scratch)
183+
184+
The following process uses charts for `elasticsearch-migrate` (which is a modified `elasticsearch-index` subchart of wire-server). If you are building an index from scratch, you can ignore "dual" writing with `additionalWriteIndex`.
185+
186+
```
187+
wget https://s3-eu-west-1.amazonaws.com/public.wire.com/charts-develop/elasticsearch-migrate-0.1.0.tgz
188+
```
189+
190+
Create a `values.yaml` to configure it:
191+
192+
```
193+
reindexType: "reindex"
194+
runReindex: false
195+
elasticsearch:
196+
host: # your elasticsearch host here
197+
index: directory_new # name of new index
198+
cassandra:
199+
host: # your cassandra host here
200+
image:
201+
tag: 5.23.0 # or whichever version you are running atm, the current method has been tested with 5.23 and 5.25
202+
```
203+
204+
This will create a new index called `directory_new` after it has been run. The name of a new index can be of your choosing, `directory_new` was selected as the previous default one was `directory`.
205+
206+
Run it with helm (mind the following command assumes some paths which might not be applicable in your installation):
207+
208+
```
209+
helm upgrade --install elasticsearch-migrate charts/elasticsearch-migrate -f values/elasticsearch-migrate/values.yaml
210+
```
211+
212+
Configure brig to use both the standard and the newly created index (usually in `values/wire-server/values.yaml`):
213+
214+
```
215+
brig:
216+
config:
217+
elasticsearch:
218+
host: elasticsearch-external
219+
index: directory # current default name of index
220+
additionalWriteIndex: directory_new # new index (should match the name set in previous step)
221+
```
222+
223+
Apply it (same assumptions regarding paths as our standard deployment process):
224+
225+
```
226+
helm upgrade --install wire-server charts/wire-server -f values/wire-server/values.yaml -f values/wire-server/values.yaml
227+
```
228+
229+
To backfill the new index, edit `values.yaml` for `elasticsearch-migrate` charts and set `runReindex` to true:
230+
231+
```
232+
reindexType: "reindex"
233+
runReindex: true
234+
elasticsearch:
235+
host: # your elasticsearch host here
236+
index: directory_new
237+
cassandra:
238+
host: # your cassandra host here
239+
image:
240+
tag: 5.23.0 # or whichever version you are running atm, the current method has been tested with 5.23 and 5.25
241+
```
242+
243+
Apply it again:
244+
245+
```
246+
helm upgrade --install elasticsearch-migrate charts/elasticsearch-migrate -f elasticsearch-migrate/values.yaml
247+
```
248+
249+
This should start a kubernetes `Job` named `elasticsearch-migrate-data` that might take several hours to run, depending on the amount of data it needs to re-create.
250+
Galley pods might get OOMKilled during this, if that is the case, increase galley memory for requests and limits (we found in Wire Cloud prod 8Gi is sufficient):
251+
252+
```
253+
galley:
254+
resources:
255+
requests:
256+
memory: 8Gi
257+
limits:
258+
memory: 8Gi
259+
```
260+
261+
Reapply:
262+
263+
```
264+
helm upgrade --install wire-server charts/wire-server -f values/wire-server/values.yaml -f values/wire-server/values.yaml
265+
```
266+
267+
And then restart `elasticsearch-migrate`.
268+
269+
After the reindexing is complete, configure wire-server to read from the new index:
270+
271+
```
272+
brig:
273+
config:
274+
elasticsearch:
275+
index: directory_new
276+
elasticsearch-index:
277+
elasticsearch:
278+
index: directory_new
279+
```
280+
281+
After verifying all is okay on the client side (check your Team Settings UI, if you can see your team user list). You can delete the old index in your ES cluster with:
282+
283+
curl -X DELETE “localhost:9200/directory”
284+
285+
## Aliasing
286+
287+
To alias an index, use the Native Elasticsearch API in your ES cluster like so:
288+
289+
```
290+
curl -X POST "localhost:9200/_aliases" -H 'Content-Type: application/json' -d '{"actions": [{"add": {"index": "directory-name-here", "alias": "alias-for-that-directory"}}]}'
291+
94292
## Troubleshooting
95293
96294
Description:

0 commit comments

Comments
 (0)