使用C#的Azure搜索索引重建策略

时间:2019-02-13 13:05:57

标签: c# indexing azure-search

我有一个Azure搜索,该搜索每5分钟索引一次Azure存储。由于存储可能偶尔也会删除,因此我一直在寻找一种处理方式。从文档中我了解到,除非您手动删除索引或重建索引。

可以进行全面重建,但我想将停机时间降至最低。我一直在寻找这样做的策略。现在,我想到了要建立第二个索引,一旦完成,就删除旧的索引。但是,感觉有点笨拙,因为我不得不跟踪索引名称。

现在看起来像这样(简化):

//create new index
searchClient.Indexes.CreateOrUpdate(index);

//update indexer
var indexer = searchClient.Indexers.Get("testindexer");
indexer.TargetIndexName = index.Name;
searchClient.Indexers.CreateOrUpdate(indexer.Name);

//reset and run indexer
searchClient.Indexers.Reset(indexer.Name);
searchClient.Indexers.Run(indexer.Name);

//at this point the new index is used

//delete old index
searchClient.Indexes.Delete(oldIndex.Name);

2 个答案:

答案 0 :(得分:1)

从文档看来,默认情况下已为您启用了增量索引: https://docs.microsoft.com/en-us/azure/search/search-howto-indexing-azure-blob-storage

此外,您可以使用“软删除”选项,以防这些删除的文件有时再次出现。

答案 1 :(得分:1)

documentation for recommended practices on reindexing data类似于您提到的方案,可能很有用。另外,如果您希望Azure搜索将来支持硬删除的数据删除策略,则有an uservoice request that you can vote on here.,正如另一个答案所提到的,今天推荐的策略是使用the soft delete option that Azure Search provides,因此如果您可以重组删除操作的方式,那么这也是一个潜在的选择。

相关问题