Reputation: 6577
I'm very new to the Azure Search Service and I'm following along with the guides that I found on the web. 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. 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? 2. Is there a better approach than just deleting the index. If there is a way to update, how do you handle scenarios where document structure has changed, for example a new field is added.
Upvotes: 0
Views: 1427
Reputation: 8634
That sample is meant to demonstrate how to call Azure Search via the .NET SDK. It should not be taken as an example of best practices.
To answer your specific questions:
Indexes.CreateOrUpdate
methods of the .NET SDK. 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 (e.g. -- 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.Upvotes: 2