使用 C# 的 Azure 搜索索引重建策略
Azure search index rebuild strategy using C#
我有一个 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);
从文档来看,增量索引似乎默认为您启用:
https://docs.microsoft.com/en-us/azure/search/search-howto-indexing-azure-blob-storage
此外,您可以使用 "soft delete" 选项,以防那些已删除的文件可能会在某个时候重新出现。
有 documentation for recommended practices on reindexing data similar to the scenario that you mention that may be useful. In addition, if you would like Azure Search to support a data deletion policy for hard deletions in the future, there is an uservoice request that you can vote on here. As the other answer mentions, the recommended policy for this today is using the soft delete option that Azure Search provides,因此,如果您可以重组删除操作的方式,那么这也是一个潜在的选择。
我有一个 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);
从文档来看,增量索引似乎默认为您启用: https://docs.microsoft.com/en-us/azure/search/search-howto-indexing-azure-blob-storage
此外,您可以使用 "soft delete" 选项,以防那些已删除的文件可能会在某个时候重新出现。
有 documentation for recommended practices on reindexing data similar to the scenario that you mention that may be useful. In addition, if you would like Azure Search to support a data deletion policy for hard deletions in the future, there is an uservoice request that you can vote on here. As the other answer mentions, the recommended policy for this today is using the soft delete option that Azure Search provides,因此,如果您可以重组删除操作的方式,那么这也是一个潜在的选择。