【问题标题】:How to create an Azure Search indexer using the REST API如何使用 REST API 创建 Azure 搜索索引器
【发布时间】:2020-04-26 10:48:04
【问题描述】:

由于 Azure 门户中的 bug,我需要使用 REST API 以编程方式创建 Azure 认知搜索数据源、索引和索引器。创建数据源或索引没有问题,但下面的 POST 请求返回以下错误。

{
    "error": {
        "code": "",
        "message": "The request is invalid. Details: dataSource : A resource without a type name was found, but no expected type was specified. To allow entries without type information, the expected type must also be specified when the model is specified.\r\n"
    }
}

以下 POST 请求是在此 page 上找到的修改示例,其中变量替换为服务名称、管理密钥、数据源名称和目标索引名称的正确名称。

POST 请求(使用邮递员)

POST https://SERVICENAME.search.windows.net/indexers?api-version=2019-05-06
Content-Type: application/json
api-key: ADMINKEY

{
  "name" : "my-json-indexer",
  "dataSourceName" : "BLOBDATASOURCE",
  "targetIndexName" : "TARGETINDEX",
  "schedule" : { "interval" : "PT2H" },
  "parameters" : { "configuration" : { "parsingMode" : "json" } }
}

【问题讨论】:

    标签: azure-cognitive-search


    【解决方案1】:

    似乎在您创建数据源时,没有提供 type 属性。

    这是两个请求:

    创建数据源

    POST https://[service name].search.windows.net/datasources?api-version=2019-05-06
    Content-Type: application/json
    api-key: [admin key for Azure Cognitive Search]
    
    {
        "name" : "my-blob-datasource",
        "type" : "azureblob",
        "credentials" : { "connectionString" : "DefaultEndpointsProtocol=https;AccountName=<account name>;AccountKey=<account key>;" },
        "container" : { "name" : "my-container", "query" : "optional, my-folder" }
    }  
    

    创建索引器

    POST https://[service name].search.windows.net/indexers?api-version=2019-05-06
    Content-Type: application/json
    api-key: [admin key for Azure Cognitive Search]
    
    {
      "name" : "my-json-indexer",
      "dataSourceName" : "my-blob-datasource",
      "targetIndexName" : "my-target-index",
      "schedule" : { "interval" : "PT2H" },
      "parameters" : { "configuration" : { "parsingMode" : "json" } },
      "fieldMappings" : [
        { "sourceFieldName" : "/article/text", "targetFieldName" : "text" },
        { "sourceFieldName" : "/article/datePublished", "targetFieldName" : "date" },
        { "sourceFieldName" : "/article/tags", "targetFieldName" : "tags" }
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 2014-11-29
      • 2020-03-03
      • 2020-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-13
      • 2016-01-12
      • 2019-02-05
      相关资源
      最近更新 更多