简体   繁体   English

Azure搜索合并索引操作返回异常

[英]Azure Search Merge Index Operation Returns Exception

I'm trying to run a batch operation to merge some changes to an existing Azure Search Index, but I keep running into this error: 我正在尝试运行批处理操作以合并对现有Azure搜索索引的某些更改,但是我一直遇到此错误:

{Microsoft.Rest.Azure.CloudException: The request is invalid. Details: parameters : Object reference not set to an instance of an object.

Here's a snippet of my code: 这是我的代码片段:

public static void UploadData<T>(List<T> data, ISearchIndexClient indexClient) where T : class
    {
        int totalFailedToIndex = 0;
        int totalPassedToIndex = 0;


        for (int i = 0; i < data.Count; i = i + 500)
        {
            var stBatch = data.Skip(i).Take(500).ToList();

            // Insert the data.
            var serviceTreeBatch = IndexBatch.Merge(stBatch);
            try
            {
                var index = indexClient.Documents.Index(serviceTreeBatch);
                totalPassedToIndex += index.Results.Count();

            }
            catch (IndexBatchException e)
            {
                totalFailedToIndex += e.IndexingResults.Where(f => !f.Succeeded).Count();
            }
            catch(Exception e)
            {
                continue;
            }
        }

    }

I've never seen this error before, and I can't seem to find anything online about it. 我以前从未见过此错误,而且似乎无法在线找到任何有关此错误的信息。 Any help would definitely be appreciated! 任何帮助将不胜感激!

Edit: Here's an example of the Type T that I'm passing in. The ProjectId is the key for these index items. 编辑:这是我传入的Type T的示例。ProjectId是这些索引项的键。 It's also important to note that this version does not have all the index values (it's a merge so I'm only uploading the values that could possibly change along with the key). 同样重要的是要注意,该版本没有所有索引值(这是一个合并,因此我仅上载可能随键一起更改的值)。 I'm wondering if the missing values is what's causing this to fail? 我想知道是否缺少值是什么导致失败?

    public class IndexItemModel
{
    /// <summary>
    /// Unique ProjectId
    /// </summary>
    public string ProjectId { get; set; }
    public string RepositoryId { get; set; }

    public IEnumerable<string> Repository_Users { get; set; }

    public string Repository_UsersString { get; set; }
}

This issue is caused by two separate problems: 此问题是由两个单独的问题引起的:

  1. The field names in the Index API request don't match the index definition (confirmed via troubleshooting). Index API请求中的字段名称与索引定义不匹配(已通过故障排除进行确认)。 The root cause was a missing [SerializePropertyNamesAsCamelCase] attribute on the model class. 根本原因是模型类上缺少[SerializePropertyNamesAsCamelCase]属性。
  2. At the time of this writing (July 2019), there is a bug in the Azure Search Index REST API that results in the unhelpful error message "Object reference not set to an instance of an object" being returned instead of a more helpful error message. 在撰写本文时(2019年7月),Azure搜索索引REST API中存在一个错误,导致返回了无用的错误消息``对象引用未设置为对象的实例''而不是更有用的错误消息。 This is a regression. 这是回归。 The expected behavior is an error message that names the unrecognized field and specifically says that the field name isn't recognized. 预期的行为是一条错误消息,该消息命名了无法识别的字段,并特别指出了无法识别的字段名称。

If anybody else comes across this unhelpful error message, double-check that your field names match between the Index API and the index definition. 如果还有其他人遇到此无用的错误消息,请仔细检查您的字段名称在Index API和索引定义之间是否匹配。 Sorry for the inconvenience caused by this bug. 抱歉给这个错误带来的不便。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM