Redisearch多索引跨文档混入问题原因与FT.ADD适配方案
Redisearch 多独立索引跨索引串数据问题
现有存储隔离实现
在单个Redisearch实例上部署多套独立索引,代码层面为每个业务类绑定专属索引实现存储隔离:
- XYZ类的
List<XYZ>类型数据,通过名为XYZ的索引写入 - ABC类的
List<ABC>类型数据,通过名为ABC的索引存储
核心异常
使用XYZ索引检索对应XYZ类数据时,归属ABC索引的文档会混入搜索结果,该问题可通过固定步骤稳定复现。
复现步骤
//declare three indexes. Some of them contain duplicate field names but this is to be expected (in real life we would have things like timestamps that spread across indexes) ft.create sample1 schema sampletext text ft.create sample2 schema sampleinteger numeric sortable ft.create sample3 schema sampletext text sampleinteger numeric //then we add a text under sample1 ft.add sample1 sample1doc 1.0 fields sampletext "hello this document is under an index called sample1" //then display all the documents associated with the index sample3 ft.search "sample3" "*" //-> prints the document above "hello this document is under..." //display all the documents associated with the index sample2 ft.search "sample2" "*" //-> the same result
异常现象补充说明
- 上述三个索引存在字段名重叠,真实业务中这类重叠字段通常为跨类通用的时间戳类公共字段
- 通过
FT.ADD向sample1索引添加仅含sampletext字段的文档后,分别通过sample2、sample3索引执行全量匹配搜索,均能检索到本应仅归属sample1索引的文档 - 按文档字段匹配规则,仅包含
sampletext字段的文档本不应出现在sample2索引的搜索结果中,当前跨索引检索的异常行为不符合设计预期
解决约束
- 目前
FT.ADD接口已被官方标记为废弃,但所使用的Redisearch C#客户端内部仍依赖FT.ADD接口实现文档写入,因此需要基于FT.ADD的调用逻辑找到可行解决方案 - 需明确异常根本原因与适配方案,恢复各索引的严格存储隔离能力
内容的提问来源于stack exchange,提问作者user15058390
相关产品推荐
相关产品推荐

