2015-12-24 69 views
0

當試圖索引文件中,我們收到此錯誤:Azure的搜索 - 錯誤

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

有誰知道爲什麼這個錯誤發生?

+0

你能否提供你試圖索引的對象的類描述? –

+0

感謝您的時間。該類是一個簡單的POCO:public class Address { public string Id {get;組; } public string Addr {get;組; } public string Country {get;組; } public int Flag {get;組; } } – user2981411

+0

您能否提供您正在嘗試索引的示例文檔? –

回答

0

該問題是由於額外致電IndexAction.Create。如果你改變你的索引代碼到這一點,將工作:

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

編譯器沒有抓住這一點,因爲IndexBatch.Create具有可採取任意數量的IndexAction<T>任何類型的T.在這種情況下,T一PARAMS參數是一個集合,它不被支持(文檔必須是對象,而不是集合)。

創建批次和操作的編程模型在SDK的1.0.0預覽版本中發生了很大變化。它會更安全,因此這樣的錯誤更有可能在編譯時被捕獲。

+0

非常感謝所有這些。我會嘗試。 – user2981411