You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Azure Cognitive Search基于Cosmos DB嵌套属性处理删除?

解决方案:Azure Cognitive Search基于Cosmos DB嵌套属性实现软删除

Azure Cognitive Search的SoftDeleteColumnDeletionDetectionPolicy不支持通过点表示法(如info.isIndexing)引用嵌套属性,仅能识别文档顶层的字段。以下是无需修改Cosmos DB原文档结构的两种可行方案:

方案1:通过Cosmos DB投影查询生成顶层字段

在Azure Cognitive Search的数据源配置中,使用Cosmos DB SQL查询将嵌套属性投影为顶层字段,让软删除策略可以识别该字段。

示例数据源配置:

{
  "name": "your-cosmos-datasource",
  "type": "cosmosdb",
  "credentials": { "connectionString": "your-cosmos-db-connection-string" },
  "container": {
    "name": "your-target-collection",
    "query": "SELECT *, c.info.isIndexing AS isIndexing FROM c"
  },
  "dataDeletionDetectionPolicy": {
    "@odata.type": "#Microsoft.Azure.Search.SoftDeleteColumnDeletionDetectionPolicy",
    "softDeleteColumnName": "isIndexing",
    "softDeleteMarkerValue": "true"
  }
}

该查询会保留原文档的所有字段,同时新增一个顶层isIndexing字段,直接映射嵌套的info.isIndexing属性,软删除策略即可基于这个顶层字段触发删除操作。

方案2:使用索引器字段映射转换嵌套属性

通过索引器的字段映射规则,将嵌套属性转换为顶层辅助字段,无需修改Cosmos DB文档。

示例索引器配置(仅展示核心配置部分):

{
  "name": "your-search-indexer",
  "dataSourceName": "your-cosmos-datasource",
  "targetIndexName": "your-search-index",
  "fieldMappings": [
    {
      "sourceFieldName": "/info/isIndexing",
      "targetFieldName": "isIndexing"
    }
  ],
  "dataDeletionDetectionPolicy": {
    "@odata.type": "#Microsoft.Azure.Search.SoftDeleteColumnDeletionDetectionPolicy",
    "softDeleteColumnName": "isIndexing",
    "softDeleteMarkerValue": "true"
  }
}

这里使用JSON路径的斜杠表示法(/info/isIndexing)引用嵌套属性,将其映射为顶层的isIndexing字段,软删除策略即可正常识别。

注意事项

  • 字段映射生成的isIndexing字段无需添加到搜索索引的字段定义中,软删除检测仅依赖数据源返回的结果字段。
  • 两种方案均不会修改Cosmos DB中的原始文档结构,仅在数据同步到Azure Cognitive Search的过程中做临时字段转换。

内容的提问来源于stack exchange,提问作者M.bo.yazan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 20:55:17