Azure 搜索索引器 : cannot create an indexer based on mongodb data source with a collection containing a field named '$ref'

标签 azure azure-cognitive-search

如标题中所述,我在创建索引器(同时使用门户 Azure 和 Rest api)时遇到奇怪的错误。

{
    "error": {
        "code": "",
        "message": "Error with data source: Additional content found in JSON reference object. A JSON reference object should only have a $ref property. Path '$id'.  Please adjust your data source definition in order to proceed."
    }
}

数据源是通过 Azure 门户创建的,未指定删除或更改策略。

comosdb (MongoDb) 中的 JSON 结构 帖子收藏

{
  "_id": {
    "$oid": "....."
  },
  "author": {
    "$ref": "user",
    "$id": {
      "$oid": "...."
    }
  },
  "_class": "com.community.domain.Post"
}

位于索引器定义下方

{
"dataSourceName": "fshco-post",
"targetIndexName": "index",
"fieldMappings": [
{
"sourceFieldName": "_class",
"targetFieldName": "class"
}

    ],
    "parameters": {
        "batchSize": 1000,
        "maxFailedItems": null,
        "maxFailedItemsPerBatch": null
    }

}

为了确认问题出在 $ref 属性上。我使用了一个包含一个文档的集合 Post,但作者字段中没有子属性 $ref,并且索引成功。

我已尝试使用技能组 **ShaperSkill ** 来修改 $ref 命名,但也没有出现相同的错误。 之后,我了解到问题可能出在技能组执行阶段之前的破解数据阶段。 indexing phases

下面是我使用过的定义技能:

 {
      "@odata.type": "#Microsoft.Skills.Util.ShaperSkill",
      "name": "#1",
      "description": null,
      "context": "/document",
      "inputs": [
        {
          "name": "refto",
          "source": "/document/author/$ref"
        },
        {
          "name": "id",
          "source": "/document/author/$id"
        }
      ],
      "outputs": [
        {
          "name": "output",
          "targetName": "post_author"  --> same name as the index attribute
        }
      ]
    }
  ]

在索引器中

    "skillsetName": "skillpostshaper",
    "outputFieldMappings": [
        {
            "sourceFieldName": "/document/post_author",
            "targetFieldName": "post_author"
        }
    ],

有什么明显我错过的事情吗?

最佳答案

您遇到的错误与您在 JSON 文件中对 $ref 的使用有关,与索引器本身无关。 JSON 文件中的 $ref 关键字是“保留字”,只能用于指向引用。正如评论的一部分所建议的,在索引数据源之前修改数据源中的字段名称,通过删除 $ref 属性或将其重命名为不同的字段名称,应该让索引器读取 JSON 文件以您期望的方式。

这里是对 JSON documentation 的引用了解更多信息。

关于Azure 搜索索引器 : cannot create an indexer based on mongodb data source with a collection containing a field named '$ref' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75034887/

相关文章:

azure - 为了触发发布管道(为构建工件配置),构建管道必须具有 "publish artifact"任务?

azure-cognitive-search - Azure 搜索突出显示部分匹配

azure - 如何返回平均值 - Azure 认知搜索或语义搜索查询

asp.net - 将 Azure 网站恢复到初始状态

sql-server - 错误: SQL71564 When migrating to Azure

c# - Azure存储,无法正确上传图片

具有可变距离的 Azure 搜索距离过滤器

azure - Azure Blob 索引器的问题

作为 API 调用运行时,Azure OpenAI 自带数据失败

azure - 我可以在不启动 AKS 群集的情况下创建它吗? (停止状态)