用 bonsai给 seafile 增加索引
故事开始
seafile 已经用了很久了,发现一个问题,对于11版本,页面右上角有一个搜索功能,但是我用了发现搜索不到东西。查了一下这个是需要单独安装 es 的,但是考虑到我的服务器资源有限。就没有安装。
但是有点恶心的是,这个搜索功能会把浏览器原本的 crtl+F 给替换了,但是我不仅不能全局检索,也无法在当前页面搜索了。
秉着能白嫖就不花钱的原则,让 deepseek 帮忙找了下有没有合适的,结果真找到了。
配置 bonsai
bonsai,简单完成账号注册后,选择elasticsearch 7.10.2部署,一键完成。
接着找到左侧菜单栏里面的- Credentials,新建一个 api,得到访问地址和账号密码。
测试一下可以访问。
配置seafile 的 index
具体配置参考官方文档
- https://cloud.seafile.com/published/seafile-manual-cn/config/seafevents-conf.md
- https://cloud.seafile.com/published/seafile-manual-cn/deploy_pro/download_and_setup_seafile_professional_server.md
修改这个/opt/seafile/conf/seafevents.conf
,找到[INDEX FILES]
[INDEX FILES]
enabled = true
interval = 10m
highlight = fvh
external_es_server = true
es_host =
es_port =
verify_cert = false
username =
password =
scheme = https
安装官方的描述,改完配置文件是需要重启 seafile 的,但是我实际测试下来,发现不需要。这里我用的是11版本,仅作参考
配置结束后,执行更新索引
/opt/seafile/seafile-server-latest/pro/pro.py search --update
本以为到这就很顺利了,配置完 seafile 就能立马用了,结果还是开心早了。
版本问题
第一个报错-版本问题
这里我一开始简单的以为这个因为常用端口换了从9200到443,所以做了个简单的校验。天真的想通过 iptables 去做端口映射,结果做完发现还是这个问题...
后来 GPT 查了,这个是 做了格式校验。
ok,既然有校验,那就把校验砍了。
根据报错提示词,查到了两个文件
# 异步模块
vim /opt/seafile/seafile-server-latest/pro/python/elasticsearch/_async/client/_base.py
# 同步模块
vim /opt/seafile/seafile-server-latest/pro/python/elasticsearch/_sync/client/_base.py
两个文件里面都有一个一个相同的格式校验
# 'X-Elastic-Product: Elasticsearch' should be on every 2XX response.
if not self._verified_elasticsearch:
# If the header is set we mark the server as verified.
if meta.headers.get("x-elastic-product", "") == "Elasticsearch":
self._verified_elasticsearch = True
# Otherwise we only raise an error on 2XX responses.
elif meta.status >= 200 and meta.status < 300:
raise UnsupportedProductError(
message=(
"The client noticed that the server is not Elasticsearch "
"and we do not support this unknown product"
),
meta=meta,
body=resp_body,
)
就是这的问题,接着把这块给换成如下部分
if not self._verified_elasticsearch:
if meta.status >= 200 and meta.status < 300:
self._verified_elasticsearch = True
改完保存以后,重新 update。
又失败了☹️
第二个报错-服务器校验 Content-Type
不通过
接着根据关键词查,查到了另一个serializer.py
文件,改完这发现,又不行了,原来是这个文件里面定义的mimetype
会在客户端还在序列化/反序列化逻辑中检查这个,不能动这个
Updating search index, this may take a while... 2025-09-04 16:22:53,636 [INFO] seafes:210 main: storage: using filesystem storage backend 2025-09-04 16:22:53,637 [INFO] seafes:212 main: index office pdf: True 2025-09-04 16:22:55,091 [ERROR] seafes:158 start_index_local: Index process init error: Unknown mimetype, not able to serialize or deserialize: application/vnd.elasticsearch+json.
那绕回去,不改这个,我们要的是改客户端发送的时候的Content-Type
,还是回到上面的两个_base
文件,在279行设置了 header,
mimetype_header_to_compat("Content-Type")
就是这儿了,把原来的Content-Type
改成我们需要的
request_headers["Content-Type"] = "application/json"
改完以后,再去 update,终于看到了胜利的曙光
数据成功推送到 bonsai 了
接着再返回 seafile 页面,搜索就可以用了🍾
[!NOTE ] tips
目前的推送,会把 txt、md 格式的文档正文都推送过去,根据个人情况可以修改这部分
/opt/seafile/seafile-pro-server-11.0.18/pro/python/seafes/constans.py
text_suffixes = [
'txt',
'md',
'markdown'
]
修改完,删除索引重新建立索引即可
./pro.py --clear
./pro.py --update