How to create the field mapping in Azure cognitive search

Hemanath Goud Kandula 1 Reputation point
2023-02-10T13:17:41.0666667+00:00

I have been using the Azure cognitive search to create the search index where the data source will be the azure SQL database.

I have created the search index for azure cognitive search and for the key index will be the id column from the table and the datatype will be fixed as edm.string type.

I have seen that we can change the datatype of id column to edm.int32 using the field mapping.

Can anyone help me with how we can able to create the field mapping for id column by changing the datatype to edm.int32

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,180 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 18,816 Reputation points
    2023-02-13T18:12:13.5533333+00:00

    Hi @Hemanath Goud Kandula

    To achieve your scenario, you can create a field mapping for the id column by changing the datatype to edm.int32.

    To do this, you will need to add a field mapping to the "fieldMappings" array of your indexer definition. The field mapping should consist of three parts:

    1.sourceFieldName: This is the name of the field in your data source (in this case, the id column in your Azure SQL database).

    1. targetFieldName: This is the name of the field in your search index. If you want to keep the same name as the source field, you can omit this property.
    2. mappingFunction: This is an optional property that allows you to apply a predefined function to transform the data. In this case, you don't need to use a mapping function as you are just changing the data type.

    Here's an example of how your field mapping would look like:

    "fieldMappings": [ { "sourceFieldName": "id", "targetFieldName": "id", "mappingFunction": null } ]
    

    This should map the id column in your Azure SQL database to the id field in your search index and change the data type to edm.int32

    See this Azure doc for more information on field mapping and supported data types in Azure Cognitive Search

    hope that helps.

    -Grace


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.