fix(v071): 全新目标实例的空索引按空基线处理
build / build (push) Successful in 1m15s

全新 WeKnora 会用空映射({})先建好索引,范围字段等第一次写入才动态生成。
首次同步在读目标当前状态时就报 "missing release scope fields" 并失败,等于
"往空的生产实例做第一次同步"这条路根本走不通。

现在:"没有范围字段 + 索引确实 0 篇文档" = 空基线;有文档却看不出归属仍然报错
(绝不把无法归属的文档当空库覆盖)。Count 与整库导出共用同一判断。

试过:make verify 15 项全绿;新增空/非空两种索引的用例;真实 sync 复现原错误。
This commit is contained in:
姚章浩
2026-10-29 06:17:26 +08:00
parent 84e8a0dfdc
commit 7d4ffdbfe5
5 changed files with 109 additions and 1 deletions
@@ -19,6 +19,17 @@ func (exporter *SearchExporter) Count(ctx context.Context, identity SearchIdenti
return 0, errors.New("invalid search identity")
}
inspection, err := exporter.inspectMapping(ctx)
if errors.Is(err, errScopeFieldsMissing) {
// 新建索引还没有范围字段:只有确实为空时才等于"这个范围 0 条"。
empty, probeErr := exporter.emptyScopeIndex(ctx)
if probeErr != nil {
return 0, probeErr
}
if empty {
return 0, nil
}
return 0, err
}
if err != nil {
return 0, err
}