Azure 搜索 - 错误

标签 azure azure-cognitive-search

当尝试索引文档时,我们收到此错误:

{"Token PropertyName in state ArrayStart would result in an invalid JSON object. Path 'value[0]'."}

我们使用 .NET 库进行索引的代码是:

using (var indexClient = new SearchIndexClient(searchServiceName, indexName, new SearchCredentials(apiKey)))
  {
      indexClient.Documents.Index(IndexBatch.Create(IndexAction.Create(documents.Select(doc => IndexAction.Create(doc)))));
  }

有人知道为什么会出现这个错误吗?

最佳答案

此问题是由于对 IndexAction.Create 的额外调用造成的。如果您将索引代码更改为此,它将起作用:

indexClient.Documents.Index(IndexBatch.Create(documents.Select(doc => IndexAction.Create(doc))));

编译器没有捕获到这个,因为 IndexBatch.Create有一个 params 参数,可以采用任意数量的 IndexAction<T>对于任何类型 T。在本例中,T 是一个集合,这是不受支持的(文档必须是对象,而不是集合)。

在 SDK 1.0.0 预览版中,用于创建批处理和操作的编程模型发生了重大变化。它将更加类型安全,这样这样的错误更有可能在编译时被捕获。

关于Azure 搜索 - 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34457885/

相关文章:

azure - 如何使用 Azure 搜索 API 进行多索引搜索?

git - 如何将特定分支发布到azure应用程序服务?

database - Azure 认知搜索能否用作某些数据的主数据库?

sql-server - Azure SQL 数据库是否支持两阶段提交 (2PC)?

c# - asp.net core如何向用户添加声明

azure - Azure 认知搜索服务中的索引存储在哪里?

Azure 搜索 SQL Server Blob 列

azure-cognitive-search - Azure 搜索 : use a single index on multiple data sources

sql - Azure SQL 数据库中的索引

azure - 从 Github 部署到 Azure 时指定应用程序根目录