简体   繁体   English

Azure搜索服务删除索引

[英]Azure Search Service Deleting an Index

I'm very new to the Azure Search Service and I'm following along with the guides that I found on the web. 我是Azure Search Service的新手,并且会跟随我在网上找到的指南。 In one of these guides they have a method such as this: 在这些指南之一中,他们具有这样的方法:

static void Main(string[] args)
{
    IConfigurationBuilder builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
    IConfigurationRoot configuration = builder.Build();

    SearchServiceClient serviceClient = CreateSearchServiceClient(configuration);
    var test = serviceClient.Indexes.GetClient("testindex");

    Console.WriteLine("{0}", "Deleting index...\n");
    DeleteHotelsIndexIfExists(serviceClient);

    Console.WriteLine("{0}", "Creating index...\n");
    CreateHotelsIndex(serviceClient);

    ISearchIndexClient indexClient = serviceClient.Indexes.GetClient("hotels");

    Console.WriteLine("{0}", "Uploading documents...\n");
    UploadDocuments(indexClient);

    ISearchIndexClient indexClientForQueries = CreateSearchIndexClient(configuration);

    RunQueries(indexClientForQueries);

    Console.WriteLine("{0}", "Complete.  Press any key to end application...\n");
    Console.ReadKey();
}

So the idea above is to delete an index if it exists, then create a new index. 因此,上面的想法是删除索引(如果存在),然后创建一个新索引。 Then generate and upload documents and then finally run a search. 然后生成并上载文档,然后最终运行搜索。 Now this all makes sense to me how it works, but one thing that troubles me is the deleting the index part. 现在,这对我来说都是有意义的,但是困扰我的一件事是删除索引部分。 Essentially what would appear to me is that they are suggesting to always delete the index and then recreate it. 从本质上讲,对我来说,他们建议始终删除索引,然后重新创建它。 Which makes me concerned. 这让我很担心。

If this is a live index, then by me deleting it even for a split of a second, wouldn't that mean that services calling search on this index will fail? 如果这是一个实时索引,那么即使我只是瞬间将其删除,这是否意味着在该索引上调用搜索的服务也会失败? The other thing that I'm concerned about is that in most cases my data will be 90% the same, I'll have some updates and newer records, maybe few deleted. 我担心的另一件事是,在大多数情况下,我的数据将保持90%相同,我将进行一些更新和更新,甚至可能删除一些记录。 But if my database has a million records, it just seems foolish to delete it all and then create it all over again. 但是,如果我的数据库有一百万条记录,那么删除所有记录然后重新创建它似乎是愚蠢的。

Is there a better approach. 有没有更好的方法。 Is there a way for me to just update the documents in the index as opposed to deleting it? 我有办法只更新索引中的文档而不是删除它吗?

So I guess this is a 2-part question. 所以我想这是一个两部分的问题。 1. If I delete the index, will it stop the searching capability while the new one is being built? 1.如果删除索引,在建立新索引时它将停止搜索功能吗? 2. Is there a better approach than just deleting the index. 2.是否有比删除索引更好的方法。 If there is a way to update, how do you handle scenarios where document structure has changed, for example a new field is added. 如果有更新的方法,如何处理文档结构已更改的情况,例如添加了新字段。

That sample is meant to demonstrate how to call Azure Search via the .NET SDK. 该示例旨在演示如何通过.NET SDK调用Azure搜索。 It should not be taken as an example of best practices. 它不应被视为最佳实践的示例。

To answer your specific questions: 要回答您的特定问题:

  1. Deleting the index will immediately cause all requests targeting that index to fail. 删除索引将立即导致所有针对该索引的请求失败。 You should not delete a live index in production. 您不应在生产中删除活动索引。 Also, there is not yet a backup/restore capability for indexes, so even if an index is not live, you shouldn't delete it unless you can restore the data from elsewhere. 此外,还没有索引的备份/还原功能,因此,即使索引不是活动的,也不应删除它,除非可以从其他位置还原数据。
  2. If you need to update documents without updating the index schema, you can achieve this with the "merge" action of the Index API. 如果您需要更新文档而不更新索引架构,则可以通过Index API的“合并”操作来实现。 There is a tutorial that covers this here . 有覆盖此教程这里 If you need to add a new field, you can do this without deleting and re-creating the index -- just use one of the Indexes.CreateOrUpdate methods of the .NET SDK. 如果需要添加新字段,则可以执行此操作而无需删除并重新创建索引-只需使用.NET SDK的Indexes.CreateOrUpdate方法之一即可。 By default this operation does not cause any index downtime. 默认情况下,此操作不会导致任何索引停机。 However, if you need to delete, rename, or change the type of an existing field, or enable new behaviors on a field (eg -- make it facetable, sortable, or part of a suggester), you'll need to create a new index. 但是,如果您需要删除,重命名或更改现有字段的类型,或在字段上启用新行为(例如,使其具有可表性,可排序或是建议者的一部分),则需要创建一个新索引。 For this reason, it is recommended that your application implement an extra layer of indirection over index names so that you can swap and re-build indexes when needed. 因此,建议您的应用程序在索引名称上实现一个间接层,以便您可以在需要时交换和重建索引。

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

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