For some not yet known reason, our XWiki sometimes looses documents from its Solr index.
As I could not find an API endpoint to trigger a reindex, I had to automate it manually using curl.
Caution: This is only a workaround! By default the index is updated on every change.
The code
start-reindex.sh
#!/bin/bash
curl 'https://wiki.example.com/xwiki/bin/admin/XWiki/XWikiPreferences?editor=globaladmin§ion=Search' \
--netrc-file xwiki.netrc -c reindex-cookies.txt -o /dev/null
FORM_TOKEN=$( curl 'https://wiki.example.com/xwiki/bin/admin/XWiki/XWikiPreferences?editor=globaladmin§ion=Search&force=1&forceEdit=1' \
-b reindex-cookies.txt | grep form_token | awk -F'value="' '{print $2;}' | awk -F'"' '{print $1;}' | head -n 1 )
curl 'https://wiki.example.com/xwiki/bin/admin/XWiki/XWikiPreferences?editor=globaladmin§ion=Search&force=1&forceEdit=1' \
-H 'content-type: application/x-www-form-urlencoded' -X POST -b reindex-cookies.txt \
--data-raw "form_token=${FORM_TOKEN}&action=reindex&wiki=&customQueryLanguage=xwql&customQuery=" -o /dev/null
rm reindex-cookies.txt
xwiki.netrc
machine wiki.example.com
login wiki-admin-user-username
password wiki-admin-user-password
How it works
- The first curl request authenticates the admin user defined in xiwiki.netrc and stores the session cookie in reindex-cookies.txt
- The second curl request simulates a user opening the solr settings page to get the form token which prevents CSRF.
- The third curl request simulates a user triggering the reindex.
- Using the session cookie is required because the form token is bound to the users session.