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

Azure AI Search原生Blob软删除配置及键映射报错问题

问题描述

我在Azure AI Search的Azure Blob Storage类型数据源中启用了原生Blob软删除,同时也开启了ADLS软删除,但验证时发现文件对应的索引文档并未被删除。根据官方要求,索引的文档键必须映射到Blob属性或元数据(比如metadata_storage_path),但尝试将metadata_storage_path映射为文档键时,收到错误提示:Keys can only contain letters, digits, underscore (_), dash (-), or equal sign (=). 由于路径必然包含特殊字符,请问如何完成metadata_storage_path到键的映射?

原索引器配置:

{
  "@odata.context": "*******.search.windows.net/$metadata#indexers/$entity",
  "@odata.etag": "\"*****************\"",
  "name": "tracking-changes-and-deletions-indexer",
  "description": null,
  "dataSourceName": "some",
  "skillsetName": "experimental-skillset-test",
  "targetIndexName": "tracking-changes-and-deletions-index",
  "disabled": null,
  "schedule": null,
  "parameters": {
    "batchSize": null,
    "maxFailedItems": null,
    "maxFailedItemsPerBatch": null,
    "base64EncodeKeys": null,
    "configuration": {
      "dataToExtract": "contentAndMetadata",
      "parsingMode": "text",
      "imageAction": "none"
    }
  },
  "fieldMappings": [
    {
      "sourceFieldName": "metadata_storage_path",
      "targetFieldName": "title",
      "mappingFunction": null
    },
    {
      "sourceFieldName": "metadata_storage_last_modified",
      "targetFieldName": "storage_last_modified",
      "mappingFunction": null
    }
  ],
  "outputFieldMappings": [],
  "cache": null,
  "encryptionKey": null
}

原索引配置:

{
  "name": "tracking-changes-and-deletions-index",
  "defaultScoringProfile": null,
  "fields": [
    {
      "name": "id",
      "type": "Edm.String",
      "searchable": true,
      "filterable": false,
      "retrievable": true,
      "stored": true,
      "sortable": false,
      "facetable": false,
      "key": true,
      "indexAnalyzer": null,
      "searchAnalyzer": null,
      "analyzer": "keyword",
      "normalizer": null,
      "dimensions": null,
      "vectorSearchProfile": null,
      "vectorEncoding": null,
      "synonymMaps": []
    },
    {
      "name": "content",
      "type": "Edm.String",
      "searchable": true,
      "filterable": true,
      "retrievable": true,
      "stored": true,
      "sortable": false,
      "facetable": false,
      "key": false,
      "indexAnalyzer": null,
      "searchAnalyzer": null,
      "analyzer": null,
      "normalizer": null,
      "dimensions": null,
      "vectorSearchProfile": null,
      "vectorEncoding": null,
      "synonymMaps": []
    },
    {
      "name": "title",
      "type": "Edm.String",
      "searchable": true,
      "filterable": true,
      "retrievable": true,
      "stored": true,
      "sortable": false,
      "facetable": false,
      "key": false,
      "indexAnalyzer": null,
      "searchAnalyzer": null,
      "analyzer": null,
      "normalizer": null,
      "dimensions": null,
      "vectorSearchProfile": null,
      "vectorEncoding": null,
      "synonymMaps": []
    },
    {
      "name": "embedding",
      "type": "Collection(Edm.Single)",
      "searchable": true,
      "filterable": false,
      "retrievable": true,
      "stored": true,
      "sortable": false,
      "facetable": false,
      "key": false,
      "indexAnalyzer": null,
      "searchAnalyzer": null,
      "analyzer": null,
      "normalizer": null,
      "dimensions": 1536,
      "vectorSearchProfile": "vector-profile-1717156292529",
      "vectorEncoding": null,
      "synonymMaps": []
    }
  ],
  "scoringProfiles": [],
  "corsOptions": null,
  "suggesters": [],
  "analyzers": [],
  "normalizers": [],
  "tokenizers": [],
  "tokenFilters": [],
  "charFilters": [],
  "encryptionKey": null,
  "similarity": {
    "@odata.type": "#Microsoft.Azure.Search.BM25Similarity",
    "k1": null,
    "b": null
  },
  "semantic": {
    "defaultConfiguration": null,
    "configurations": []
  },
  "vectorSearch": {
    "algorithms": [
      {
        "name": "vector-config-1717156300344",
        "kind": "hnsw",
        "hnswParameters": {
          "metric": "cosine",
          "m": 4,
          "efConstruction": 400,
          "efSearch": 500
        },
        "exhaustiveKnnParameters": null
      },
      {
        "name": "vector-config-1718463795492",
        "kind": "exhaustiveKnn",
        "hnswParameters": null,
        "exhaustiveKnnParameters": {
          "metric": "cosine"
        }
      }
    ],
    "profiles": [
      {
        "name": "vector-profile-1717156292529",
        "algorithm": "vector-config-1717156300344",
        "vectorizer": "vectorizer-1717156312140",
        "compression": null
      }
    ],
    "vectorizers": [
      {
        "name": "vectorizer-1717156312140",
        "kind": "customWebApi",
        "azureOpenAIParameters": null,
        "customWebApiParameters": {
          "httpMethod": "POST",
          "uri": "***********************************",
          "timeout": "PT3M50S",
          "authResourceId": null,
          "httpHeaders": {},
          "authIdentity": null
        },
        "aiServicesVisionParameters": null,
        "amlParameters": null
      }
    ],
    "compressions": []
  }
}
解决方案

使用Azure AI Search的字段映射函数对metadata_storage_path进行转换,生成符合键规则的唯一字符串,推荐两种实用方法:

方法1:Base64编码

通过base64Encode函数将路径编码,编码后的字符串仅包含合法字符,且可反向解码还原原路径,适合需要保留路径可追溯性的场景。

修改后的索引器配置(重点为fieldMappings部分):

{
  "@odata.context": "*******.search.windows.net/$metadata#indexers/$entity",
  "@odata.etag": "\"*****************\"",
  "name": "tracking-changes-and-deletions-indexer",
  "description": null,
  "dataSourceName": "some",
  "skillsetName": "experimental-skillset-test",
  "targetIndexName": "tracking-changes-and-deletions-index",
  "disabled": null,
  "schedule": null,
  "parameters": {
    "batchSize": null,
    "maxFailedItems": null,
    "maxFailedItemsPerBatch": null,
    "base64EncodeKeys": null,
    "configuration": {
      "dataToExtract": "contentAndMetadata",
      "parsingMode": "text",
      "imageAction": "none"
    }
  },
  "fieldMappings": [
    {
      "sourceFieldName": "metadata_storage_path",
      "targetFieldName": "id",
      "mappingFunction": {
        "name": "base64Encode",
        "parameters": { "useHttpServerUtilityUrlTokenEncode": false }
      }
    },
    {
      "sourceFieldName": "metadata_storage_path",
      "targetFieldName": "title",
      "mappingFunction": null
    },
    {
      "sourceFieldName": "metadata_storage_last_modified",
      "targetFieldName": "storage_last_modified",
      "mappingFunction": null
    }
  ],
  "outputFieldMappings": [],
  "cache": null,
  "encryptionKey": null
}

方法2:SHA256哈希

通过sha256Hash函数生成路径的哈希值,哈希值固定为64个合法字符,适合不需要还原原路径、仅需保证唯一性的场景。

修改后的索引器配置(重点为fieldMappings部分):

{
  "@odata.context": "*******.search.windows.net/$metadata#indexers/$entity",
  "@odata.etag": "\"*****************\"",
  "name": "tracking-changes-and-deletions-indexer",
  "description": null,
  "dataSourceName": "some",
  "skillsetName": "experimental-skillset-test",
  "targetIndexName": "tracking-changes-and-deletions-index",
  "disabled": null,
  "schedule": null,
  "parameters": {
    "batchSize": null,
    "maxFailedItems": null,
    "maxFailedItemsPerBatch": null,
    "base64EncodeKeys": null,
    "configuration": {
      "dataToExtract": "contentAndMetadata",
      "parsingMode": "text",
      "imageAction": "none"
    }
  },
  "fieldMappings": [
    {
      "sourceFieldName": "metadata_storage_path",
      "targetFieldName": "id",
      "mappingFunction": {
        "name": "sha256Hash"
      }
    },
    {
      "sourceFieldName": "metadata_storage_path",
      "targetFieldName": "title",
      "mappingFunction": null
    },
    {
      "sourceFieldName": "metadata_storage_last_modified",
      "targetFieldName": "storage_last_modified",
      "mappingFunction": null
    }
  ],
  "outputFieldMappings": [],
  "cache": null,
  "encryptionKey": null
}
后续步骤
  1. 保存修改后的索引器配置
  2. 若已有索引数据,重置索引器以确保所有文档使用新键重新生成
  3. 运行索引器,验证软删除功能:删除Blob后等待索引器执行,检查对应索引文档是否被移除

内容的提问来源于stack exchange,提问作者FreeGor

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 16:14:52