コード例 #1
0
        protected async Task SendDocuments(IEnumerable <Dictionary <string, object> > documents)
        {
            var batch = new
            {
                value = documents
            };
            var azureSearchHelper = new AzureSearchHelper(IndexName, 0);
            var response          = await azureSearchHelper.SendDocumentsAsync(batch);

            var json = await response.Content.ReadAsStringAsync();

            var results  = JObject.Parse(json);
            var value    = results["value"];
            var statuses = value.Children();
            var errors   = statuses.Where(i => !(bool)i["status"]);

            if (errors.Any())
            {
                var groups = errors.GroupBy(i => (string)i["errorMessage"]);
                var first  = groups.First();
                throw new Exception(String.Format("Error count: total {0}, distinct {1}. First error: key {2}, message {3}",
                                                  errors.Count(), groups.Count(), (string)first.First()["key"], first.Key));
            }
        }