首页 > 解决方案 > 在创建新操作“IndexBatch.New(actions)”时,一个请求中允许多少个文档 Azure 搜索?

问题描述

我没有在一个请求中发布 Azure 最大限制文档。

只是我想知道是否有任何官方链接显示根据购买的计划在 azure 服务器中每个索引器的最大限制点击我

这里天蓝色的官方索引器限制了链接

在创建批次的代码下方

public virtual void PostBulkDataToAssortmentIndex(ISearchFilterResult result)
{
    var itemFilters = _searchManager.GetAllFilters();

    IEnumerable<ISearchItem> items;
    List<IndexAction<AzureSearchItem>> actionList = new List<IndexAction<AzureSearchItem>>();
    for (int i = 0; i < result.Items.Count; i = i + 32000)
    {
        actionList.Clear();
        items = result.Items.Skip(i).Take(32000);

        foreach (var item in items)
        {
            actionList.Add(IndexAction.MergeOrUpload(FormatSearchItem(item, itemFilters)));
        }

        // Post documents to index
        PostBulkAssortmentDocuments(actionList.AsEnumerable());
    }
}
public virtual void PostBulkAssortmentDocuments(IEnumerable<IndexAction<AzureSearchItem>> actions)
{
    var batch = IndexBatch.New(actions);

    try
    {
        var data = GetIndexClient(IndexName).Documents.Index(batch);
        var passResultCount = data.Results.Where(x => x.Succeeded).Count();
        var failResultCount = data.Results.Where(x => x.Succeeded == false).Count();
        var MessageResult = data.Results.Where(x => !string.IsNullOrEmpty(x.ErrorMessage));
        var keyResult = data.Results.Where(x => !string.IsNullOrEmpty(x.Key)).Select(x => x.Key).ToList();
        var unikKey = keyResult.Distinct().ToList();
    }
    catch (IndexBatchException e)
    {
        // Sometimes when your Search service is under load, indexing will fail for some of the documents in
        // the batch. Depending on your application, you can take compensating actions like delaying and
        // retrying. For this simple demo, we just log the failed document keys and continue.
        Console.WriteLine(
            "Failed to index some of the documents: {0}",
            String.Join(", ", e.IndexingResults.Where(r => !r.Succeeded).Select(r => r.Key)));
    }
}

注意:根据 Azure 文档,我不确定,但仅1000允许每批次的文档发布限制,但出于测试目的,我通过了0 documents in IndexBatch.New(actions);

然后 Azure 引发异常。

'The request is invalid. Details:
 actions: No indexing actions found in the request. Please include between 1 and 32000 indexing actions in your request.
'

如果我通过32001每份文件IndexBatch.New(actions);

然后 Azure 引发异常。

The request is invalid. Details: actions: Too many indexing actions found in the request: 32001. Please include between 1 and 32000 indexing actions in your request.

标签: azureazure-cognitive-searchazure-search-.net-sdk

解决方案


As per the documentation, the limit is 1000 documents or 16MB whichever comes first.

This approach is more flexible than the pull model because you can upload documents individually or in batches (up to 1000 per batch or 16 MB, whichever limit comes first). The push model also allows you to upload documents to Azure Cognitive Search regardless of where your data is.


推荐阅读