自定义 WebApi 技能不填充索引

Custom WebApi Skill does not populate index

我是 Azure 搜索的新手,我目前正在设置一个环境以根据某些详细信息为图像编制索引。 我已经建立了一个索引,在其他字段中,有一个我命名为 details.

的复杂字段的集合

为了填充 details 字段,我在我的索引器上设置了一个 Azure 函数作为 WebApiSkill,它接收 uri 作为输入,returns details.

According to the example from the documentation,函数收到一个application/jsonPOST请求如下:

{
    "values": [
        {
            "recordId": "1",
            "data": {
                "uri": "..."
            }
        },
        ...
    ]
}

..并立即 returns 一个 OkObjectResult 和相应的 json 响应:

{
    "values": [
        {
            "recordId": "1",
            "data": {
                "details": [
                    {
                        "detailName": "...",
                        "detailRatio": "..."
                    }, {
                        "detailName": "...",
                        "detailRatio": "..."
                    }
                ]
            }
        },
        ...
    ]
}

我的问题是,即使我遵循了关于如何为索引器的技能集设置自定义技能的文档,并且尽管以上所有内容看起来结构正确,但索引图像上的 details 仍然没有填充,它只是显示为一个空列表。 以下是对我的索引进行空搜索的结果:

{
    "@odata.context": "https://{search}.search.windows.net/indexes('{index}')/$metadata#docs(*)",
    "value": [
        {
            "@search.score": 1,
            "id": "aHR0CHM6Ly9yZWxhdGl...",
            "uri": "{link}",
            "details": []
        }
}

通过控制台日志跟踪 Azure 函数的执行,可以看出索引器确实在执行它并接收结果,所以我认为这不是连接问题或函数代码的问题。

我想知道这是否常见?如果没有,我应该采取什么步骤来尝试找出索引器拒绝正确填充索引的原因?


这是我的 indexes/indexer/skillset 中的一些代码片段。 对于此处的任何混淆,我深表歉意,因为其中一些必须通过代码 (C#) 生成,而另一些是在 Azure 门户中或通过 POST 请求生成的。据我所知,所有这些都归结为相同的,但我目前正在将所有这些转换为 POST 请求。

索引:

{
    "id": "...",
    "uri": "...",
    "details": [
        {
            "detailName": "...",
            "detailRatio": "..."
        }, {
            "detailName": "...",
            "detailRatio": "..."
        }
    ]
}

技能组合:

{
  "name": "...",
  "description": "...",
  "skills":
  [
    {
      "@odata.type": "#Microsoft.Skills.Custom.WebApiSkill",
      "uri": "https://{azure-function}.azurewebsites.net/api/{function}?code={code}",
      "context": "/document",
      "inputs": [
        {
          "name": "uri",
          "source": "/document/uri"
        }
      ],
      "outputs": [
        {
          "name": "details",
          "targetName": "details"
        }
      ]
    }
  ]
}

索引器:

new Indexer(
                name: indexerName,
                dataSourceName: dataSourceName,
                targetIndexName: indexName,
                skillsetName: skillsetName,
                fieldMappings: new List<FieldMapping>
                {
                    new FieldMapping
                    {
                        SourceFieldName = "metadata_storage_path",
                        TargetFieldName = "uri"
                    }
                },
                schedule: new IndexingSchedule {
                    Interval = new TimeSpan(0, 10, 0)
                },
                parameters: new IndexingParameters
                {
                    Configuration = new Dictionary<string, object>
                    {
                        ["imageAction"] = "generateNormalizedImages"
                    }
                }
            );

您的索引器定义缺少 outputFieldMappings 以指定 details 的数据应来自何处。参见 https://docs.microsoft.com/en-us/rest/api/searchservice/create-indexer#outputfieldmappings

你的技能context"/document"targetName"details",所以结果会是"/document/details"

"outputFieldMappings": [
  {
    "sourceFieldName": "/document/details",
    "targetFieldName": "details"
  }
]