Daevin
Daevin

Reputation: 901

Update Azure search document schema

I'm encountering an error when trying to update an Azure search document schema through a code-first approach.

Our current entity has the schema:

public class SearchDocument
{
    [DataAnnotations.Key]
    public string ID;
    [IsSearchable]
    public string Title;
    [IsSearchable]
    public string Content;
}

but I want to add a field so it becomes this:

public class SearchDocument
{
    [DataAnnotations.Key]
    public string ID;
    [IsSearchable]
    public string Title;
    [IsSearchable]
    public string Content;
    [IsSortable]
    public bool Prioritize;
}

and when running a re-indexing query, I get the error:

"The request is invalid. Details: parameters : The property 'Prioritize' does not exist on type 'search.documentFields'. Make sure to only use property names that are defined by the type."

Which makes sense... but is there a way check beforehand if the schema matches, and update the Azure schema? I know other cloud databases, like Parse (dead) and Backendless (may have changed since I last used it), had automatic entity updating based on the entity schema POSTed, so is there any way to do this in Azure?

I've found a couple articles on MSDN about updating the indexers, but haven't been able to test (due to a closed dev environment... I know, I'm sorry).

One thing in particular that concerns me is the warning in the first link:

Important
Currently, there is limited support for index schema updates. Any schema 
updates that would require re-indexing such as changing field types are not 
currently supported.

So is this even possible? Or do I have to update the schema locally and then log into the Azure portal and update the indexer schema manually? Any help is very appreciated!

Upvotes: 2

Views: 1250

Answers (1)

Liam Cavanagh - MSFT
Liam Cavanagh - MSFT

Reputation: 1464

Azure Search does support incremental changes to an Azure Search index. What this means is that you are able to add new fields (as you are doing here with your Prioritize field). Based on what you have stated, it looks like you are using the .NET SDK. For that reason, I wonder if you have tried the CreateOrUpdate index operation? For example:

serviceClient.Indexes.CreateOrUpdate

Upvotes: 1

Related Questions