1

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

{"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)))));
  }

有谁知道为什么会发生这个错误?

4

1 回答 1

1

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

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

编译器没有捕捉到这一点,因为IndexBatch.Create它有一个 params 参数,它可以为任何类型的 T 取任意数量的参数IndexAction<T>。在这种情况下,T 是一个不受支持的集合(文档必须是对象,而不是集合)。

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

于 2015-12-26T18:44:10.713 回答