文档不会出现在 Azure 文档中

Documents do not appear in Azure Documents

我想在测试应用程序中创建搜索索引。

我有一个要发送到 azure 搜索索引的对象列表。

使用以下代码我自己创建了索引:

  await client.Indexes.CreateAsync(myIndexDefinition);

这有效,我可以在门户中看到具有定义字段的索引。

现在我尝试添加文档。

using (SearchIndexClient index = client.Indexes.GetClient(cityIndexName))
{
     List<IndexAction> items = cities.Select(CreatecCtion).ToList();

     var batch = new IndexBatch(items);
     await index.Documents.IndexAsync(batch);
}

[...]

private IndexAction CreateACtion(city city)
{  
    var doc = new Document
    {
        { "CityId", city.Id }
    };

    var action = new IndexAction(IndexActionType.Upload, doc);

    return action;
}

在 运行 代码之后,所有项目的结果都表明它们是成功的,并且包含我设置的 ID。但是当我查看此索引的门户时,计数为 0。

任何提示我做错了什么?

墨菲定律。现在(在上次更新大约 30 分钟后)它们出现了。

主页上的统计数据似乎没有立即刷新。

希望这对其他人有帮助:)

索引统计数据是异步更新的。即使调用Indexes.GetStats,结果也会稍微落后一点。如果您想在索引后立即获得准确的文档计数,请使用 Documents.Count.