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

修改Azure Cognitive Search索引:网站搜索功能异常求助

解决Azure Cognitive Search仅返回计数和分数、索引JSON修改丢失的问题

一、修复索引JSON修改后丢失的问题

  • 不要直接在Azure门户的可视化索引编辑器里修改JSON,编辑器会覆盖手动修改内容。正确流程:
    1. 用Azure CLI导出当前索引定义到本地文件:
      az search index show --name your-index-name --resource-group your-rg --service-name your-search-service --output json > index-definition.json
      
    2. 在本地编辑器(如VS Code)中修改index-definition.json,确保配置好需要返回的字段及属性
    3. 用CLI重新覆盖更新索引:
      az search index create --name your-index-name --resource-group your-rg --service-name your-search-service --file index-definition.json --overwrite
      

二、配置索引与索引器,实现返回段落/标题及页面链接

1. 定义索引所需字段

索引必须包含可检索、可搜索的目标字段,示例JSON:

{
  "name": "your-index-name",
  "fields": [
    { "name": "id", "type": "Edm.String", "key": true, "retrievable": true },
    { "name": "pageUrl", "type": "Edm.String", "retrievable": true },
    { "name": "title", "type": "Edm.String", "retrievable": true, "searchable": true },
    { "name": "content", "type": "Edm.String", "retrievable": true, "searchable": true },
    { "name": "@search.score", "type": "Edm.Double", "retrievable": true }
  ]
}
  • pageUrl:存储对应网站页面的链接
  • title:提取自HTML页面的标题
  • content:HTML解析后的文本内容,需设retrievable: true才能返回

2. 配置Blob索引器解析HTML并映射字段

索引器需启用HTML解析规则,将Blob元数据/内容映射到索引字段:

{
  "name": "your-blob-indexer",
  "dataSourceName": "your-blob-datasource",
  "targetIndexName": "your-index-name",
  "parameters": {
    "configuration": {
      "parsingMode": "html",
      "indexedFileNameExtensions": ".html",
      "metadataStoragePath": "full"
    }
  },
  "fieldMappings": [
    { 
      "sourceFieldName": "metadata_storage_path", 
      "targetFieldName": "pageUrl",
      "mappingFunction": {
        "name": "replace",
        "parameters": {
          "pattern": "https://your-storage-account.blob.core.windows.net/your-container/",
          "replacement": "https://your-website.com/"
        }
      }
    },
    { "sourceFieldName": "metadata_title", "targetFieldName": "title" },
    { "sourceFieldName": "content", "targetFieldName": "content" }
  ]
}
  • parsingMode: html:让索引器自动解析HTML提取文本和元数据
  • replace映射函数:将Blob存储路径替换为实际网站页面URL

3. 调用搜索API时指定返回内容

发起搜索请求时,必须通过select参数指定要返回的字段,如需高亮关键词片段,可搭配highlight参数:

{
  "search": "your-keyword",
  "select": "pageUrl,title",
  "highlight": "content",
  "highlightPreTag": "<mark>",
  "highlightPostTag": "</mark>",
  "top": 10
}

三、常见问题排查

  • 字段未返回:检查索引字段的retrievable是否设为true,且搜索请求的select参数包含该字段
  • HTML标题未提取:确认HTML文件包含<title>标签,若索引器无法自动抓取,可添加技能集从HTML内容中提取标题
  • 页面链接映射错误:调整replace函数的pattern和replacement参数,匹配你的存储路径与网站URL规则

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 11:47:21