如何在 Azure 搜索中使用复杂的 targetField 创建字段映射

Ben*_*erg 6 azure azure-cognitive-search

我使用 Azure 搜索索引器对 MongoDB CosmosDB 中的文档进行索引,该数据库包含带有名为 的字段的对象_id。由于 Azure 搜索不允许在索引中的字段名称开头使用下划线,因此我想创建字段映射。

Cosmos 中的 JSON 结构 --> 索引中的结构

{
  "id": "test"
  "name": "test",
  "productLine": {
     "_id": "123",       --> "id": "123"
     "name": "test"
  }
}
Run Code Online (Sandbox Code Playgroud)

文档正是以这种情况作为示例,但仅适用于顶级字段。

"fieldMappings" : [ { "sourceFieldName" : "_id", "targetFieldName" : "id" } ]}

我尝试了以下方法:

"fieldMappings" : [ { "sourceFieldName" : "productLine/_id", "targetFieldName" : "productLine/id" } ] }

这会导致错误:

Value is not accepted. Valid values: "doc_id", "name", "productName".

为作为子字段的目标字段创建映射的正确方法是什么?

816*_*128 4

无法直接映射子字段。您可以通过向索引器添加具有Shaper 认知技能的技能组以及输出字段映射来解决此问题。

您还需要将认知服务资源附加到技能组。塑造者技能不需要付费,但附加认知服务资源可以让您每天处理 20 多个文档

塑造技能

{
  "@odata.type": "#Microsoft.Skills.Util.ShaperSkill",
  "context": "/document",
  "inputs": [
    {
      "name": "id",
      "source": "/document/productLine/_id"
    },
    {
      "name": "name",
      "source": "/document/productLine/name"
    }
  ],
  "outputs": [
    {
      "name": "output",
      "targetName": "renamedProductLine"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

索引器技能组和输出字段映射

"skillsetName": <skillsetName>,
"outputFieldMappings": [
    {
        "sourceFieldName": "/document/renamedProductLine",
        "targetFieldName": "productLine"
    }
]
Run Code Online (Sandbox Code Playgroud)