当尝试索引文档时,我们收到此错误:
{"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/