Using Azure Cognitive Search APIs directly

You can of course go beyond the normal behavior and APIs that come with Examine. If you want to use the Azure Cognitive Search APIs directly you can access them directly from ExamineX. The Azure Cognitive Search services are exposed as properties of ExamineX.AzureSearch.AzureSearchIndex. Otherwise you can also create your own instances of ISearchServiceClient or ISearchIndexClient.

NOTE: Because of the dynamic nature of Umbraco data, all data stored in the Azure Cognitive Search indexes created by ExamineX are not strongly typed and are based off of the dictionary based model Microsoft.Azure.Search.Models.Document.

To access these services you will need to cast the IIndex reference from IExamineManager to AzureSearchIndex.

Example:

if (!_examineManager.TryGetIndex(
    Constants.UmbracoIndexes.ExternalIndexName, 
    out var externalIndex)
    || !(externalIndex is AzureSearchIndex azureSearchIndex))
{
    throw new InvalidOperationException(
        $"No index found with name {Constants.UmbracoIndexes.ExternalIndexName} or it's type is not {typeof(AzureSearchIndex)}");
}

ISearchServiceClient searchServiceClient = azureSearchIndex.ServiceClient;
ISearchIndexClient searchIndexClient = azureSearchIndex.IndexClient;

Querying/Indexing

If you prefer to work directly with Azure Cognitive Search APIs to query or update your index data then you can use the exposed ISearchIndexClient mentioned above. Since Azure Cognitive Search has many more features than are exposed by Examine/ExamineX you will have to use these APIs to access those advanced features.

One of the great benefits of ExamineX is that it will ensure your indexes are always in sync with your Umbraco data without you having to do anything but also giving you the flexibility to use Azure Search directly.

Index modifications

It is possible to completely configure and modify the Azure Search indexes created with ExamineX using the ISearchServiceClient however it is advised to not remove any indexes, indexers, fields, field mappings or custom analyzers created with ExamineX otherwise unexpected errors may result.