---
title: Registering custom data types for Azure Search
related:
  - https://docs.kentico.com/13/configuring-xperience/setting-up-search-on-your-website/using-azure-cognitive-search/creating-azure-search-indexes.md
  - https://docs.kentico.com/13/configuring-xperience/setting-up-search-on-your-website/using-azure-cognitive-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 index fields and the fields of objects in Xperience each use a different set of data types. See the [Supported data types (Azure Search)](https://docs.microsoft.com/en-us/rest/api/searchservice/supported-data-types) article for details.

When building Azure Search indexes, Xperience performs data type mapping and conversions for field values. By default, the following data type mapping is used:

| Xperience field data type                | C# type  | Azure Search data type |
| ---------------------------------------- | -------- | ---------------------- |
| Boolean (Yes/No)                         | bool     | Edm.Boolean            |
| Date<br>Date and time                    | DateTime | Edm.DateTimeOffset     |
| Decimal number                           | decimal  | Edm.Double             |
| Floating point number (Double precision) | double   | Edm.Double             |
| Integer number                           | int      | Edm.Int32              |
| Long integer number                      | long     | Edm.Int64              |
| Long text<br>Text                        | string   | Edm.String             |
| Time interval                            | TimeSpan | Not mapped             |
| Unique identifier (GUID)                 | Guid     | Edm.String             |

If you wish to add values with a custom data type into Azure Search indexes, you first need to register the given data type, and prepare a conversion function that maps the type to one of the types supported by Azure Search. You can also use the same approach if you wish to change how the default Xperience data types map to Azure Search types.

1. Open your Xperience solution in Visual Studio.
2. Create a [custom module class](https://docs.kentico.com/13/custom-development/creating-custom-modules/initializing-modules-to-run-custom-code.md).
3. Override the module's **OnInit** method and call the **RegisterMapping** method of the **CMS.Search.Azure.DataMapper** class. The method's parameters specify:
   - The original C# data type
   - The corresponding value from the **Microsoft.Azure.Search.Models.DataType** enumeration
   - A conversion method
4. Implement the conversion methods used in your **RegisterMapping** calls.
5. Also deploy the custom module class to the MVC application (otherwise indexing may not work correctly for changes performed through the live site).

When creating Azure Search indexes, the system now uses the specified data types for the appropriate fields.

> **Note:** **Index rebuild required**
>
> To apply the custom data types to existing Azure Search indexes:
>
> 1. Sign in to the Xperience administration interface.
> 2. Open the **Smart search** application.
> 3. **Rebuild** any related Azure Search indexes.

## Example

The following example demonstrates how to re-map the **Decimal number** data type of Xperience fields to the **Edm.String** data type used by Azure Search.

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

1. Open your Xperience solution in Visual Studio.
2. [Add a custom assembly](https://docs.kentico.com/13/custom-development/adding-custom-assemblies.md) (_Class Library_ project) with class discovery enabled to the solution, or re-use an existing assembly.
3. Reference the project from both your live site and Xperience administration (_CMSApp_) projects.

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

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

   ```csharp

   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();

           // Registers custom mapping of the decimal data type in Xperience to strings in Azure Search indexes
           DataMapper.Instance.RegisterMapping(typeof(decimal), Microsoft.Azure.Search.Models.DataType.String, ConvertDecimalToString);
       }

       // Converts decimal values to strings
       // The resulting strings use ',' as the group separator, '.' as the decimal separator, and two decimal places
       private string ConvertDecimalToString(object decimalValue)
       {
           return ((decimal)decimalValue).ToString("N2", System.Globalization.CultureInfo.InvariantCulture);
       }
   }

   ```
2. Save all changes and **Build** the _SearchCustomization_ project.
3. Sign in to the Xperience administration interface.
4. Open the **Smart search** application and **Rebuild** your Azure indexes.

Any Xperience object fields that use the _Decimal number_ data type are now created as _Edm.String_ type fields within Azure Search indexes.
