---
title: Setting analyzers for Azure Search
related:
  - https://docs.kentico.com/k11/configuring-kentico/setting-up-search-on-your-website/using-azure-search/creating-azure-search-indexes.md
  - https://docs.kentico.com/k11/configuring-kentico/setting-up-search-on-your-website/using-azure-search/customizing-azure-search.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

Azure Search uses [Language analyzers](https://docs.microsoft.com/en-us/rest/api/searchservice/language-support) to process text values. By default, searchable fields are analyzed with the [Apache Lucene Standard analyzer](http://lucene.apache.org/core/4_9_0/analyzers-common/index.html). Because Azure Search supports a variety of languages, it additionally provides other text analyzers with more advanced capabilities for specific languages.

If you wish to assign a specific analyzer to the fields of an index, [customize](https://docs.kentico.com/k11/configuring-kentico/setting-up-search-on-your-website/using-azure-search/customizing-azure-search.md) the functionality that Kentico uses to build Azure Search indexes:

1. Open your Kentico solution in Visual Studio.
2. Create a [custom module class](https://docs.kentico.com/k11/custom-development/creating-custom-modules/initializing-modules-to-run-custom-code.md).
3. Override the module's **OnInit** method and assign a handler to the **DocumentFieldCreator.Instance.CreatingField.After** event.
4. Perform the following in the event's handler method:

   1. Write a condition to limit which search indexes and fields are affected by the analyzer customization (using values of the **SearchIndex** and **SearchField** properties of the handler's _CreateFieldEventArgs_ parameter).
   2. Access the **Field** property of the handler's _CreateFieldEventArgs_ parameter, and assign a valid [analyzer name](https://docs.microsoft.com/en-us/rest/api/searchservice/language-support) into one of its _Analyzer_ properties.

      > **Info:** **Field analyzer properties**
      >
      > The **Field** class (Microsoft.Azure.Search.Models.Field) offers the following properties for setting the analyzer:
      >
      > - **Analyzer**
      > - **IndexAnalyzer** (used at indexing time)
      > - **SearchAnalyzer** (used at search time)For more information, see the **Index Attributes** section of the [Create Index](https://docs.microsoft.com/en-us/rest/api/searchservice/create-index) article.
5. Sign in to the Kentico administration interface.
6. Open the **Smart search** application and **Rebuild** any related Azure Search indexes.

The customized Azure Search index fields now use the specified language analyzer.

## Example

The following example demonstrates how to set the language analyzer for the _skudescription_ field of an Azure Search index named _dg-store_.

Start by preparing a separate project in your Kentico solution for the custom module class:

1. Open your Kentico solution in Visual Studio.
2. Create a new _Class Library_ project in the Kentico solution named **SearchCustomization**.
3. Add references to the required Kentico libraries (DLLs) for the new project:

   1. Right-click the project and select **Add -> Reference**.
   2. Switch to the **Browse** tab, click **Browse**, and navigate to the  _**Lib**_  folder of your Kentico web project.
   3. Add references to the following libraries:

      - **CMS.Base.dll**
      - **CMS.Core.dll**
      - **CMS.DataEngine.dll**
      - **CMS.Search.Azure.dll**
4. Right-click the _SearchCustomization_ project in the **Solution Explorer** and select **Manage NuGet Packages**.
5. Install the **Microsoft.Azure.Search** package.
6. Reference the _SearchCustomization_ project from the Kentico web project _(CMSApp_ or _CMS)_.
7. Edit the _SearchCustomization_ project's **AssemblyInfo.cs** file (in the _Properties_ folder).
8. Add the **AssemblyDiscoverable** assembly attribute:

   ```csharp

   using CMS;

   [assembly:AssemblyDiscoverable]

   ```

Continue by implementing the custom module class and rebuilding the related search index:

1. Create a new class named **CustomAzureSearchModule** under the _SearchCustomization_ project, with the following code:

   ```csharp

   using System;

   using CMS;
   using CMS.DataEngine;
   using CMS.Search.Azure;

   // Registers the custom module into the system
   [assembly: RegisterModule(typeof(CustomAzureSearchModule))]

   public class CustomAzureSearchModule : Module
   {
       // Module class constructor, the system registers the module under the name "CustomAzureSearch"
       public CustomAzureSearchModule()
           : base("CustomAzureSearch")
       {
       }

       // Contains initialization code that is executed when the application starts
       protected override void OnInit()
       {
           base.OnInit();

           // Assigns a handler to the CreatingField.After event for Azure Search indexes
           DocumentFieldCreator.Instance.CreatingField.After += UseCustomSearchAnalyzer;
       }

       private void UseCustomSearchAnalyzer(object sender, CreateFieldEventArgs e)
       {
           string indexName = e.SearchIndex.IndexCodeName;
           string fieldName = e.SearchField.FieldName;

           // Sets the 'en.microsoft' analyzer for the 'skudescription' field in the 'dg-store' index
           if (indexName.Equals("dg-store", StringComparison.InvariantCultureIgnoreCase)
               && fieldName.Equals("skudescription", StringComparison.InvariantCultureIgnoreCase))
           {
               e.Field.Analyzer = "en.microsoft";
           }
       }
   }

   ```
2. Save all changes and **Build** the _SearchCustomization_ project.
3. Sign in to the Kentico administration interface.
4. Open the **Smart search** application and **Rebuild** the _dg-store_ index.

The _skudescription_ field of the _dg-store_ index now uses the "en.microsoft" language analyzer, both during indexing and at search time.
