Populate Azure AI Search Field with Custom Skills: A Complete Guide (2026)

Discover how to enhance your Azure AI Search results by populating fields with custom skills. This complete guide covers setting up skills, functions, and troubleshooting.

Populate Azure AI Search Field with Custom Skills: A Complete Guide (2026)

Populate Azure AI Search Field with Custom Skills: A Complete Guide (2026)

Azure Cognitive Search offers powerful capabilities to enhance search results by integrating custom AI skills. In this guide, we will explore how to populate the ParsedDate field in an Azure Search Index using a custom skill. This is particularly useful for creating scoring profiles that leverage freshness, significantly improving search relevance.

Key Takeaways

  • Learn how to create and use a custom Web API skill in Azure Cognitive Search.
  • Understand the process of setting up an index, skillset, and indexer.
  • Discover how to troubleshoot common issues when fields return null values.
  • Gain insights into creating scoring profiles based on freshness.

By harnessing custom skills, you can extract and manipulate data like dates from file names, enhancing the search capabilities of your applications. This tutorial will guide you through setting up a custom skill, configuring it in Azure Search, and ensuring your fields are populated as expected.

Prerequisites

  • Basic knowledge of Azure Cognitive Search.
  • An Azure account with access to Cognitive Search services.
  • Familiarity with REST APIs and JSON.
  • Visual Studio Code or any text editor for editing JSON configurations.

Step 1: Define Your Azure Search Index

Before creating a custom skill, ensure that your Azure Search Index is properly defined. This index should include a field for ParsedDate.


{
  "name": "my-index",
  "fields": [
    {"name": "id", "type": "Edm.String", "key": true},
    {"name": "content", "type": "Edm.String"},
    {"name": "parsedDate", "type": "Edm.DateTimeOffset"}
  ]
}

Ensure this configuration is applied in the Azure portal or via Azure CLI.

Step 2: Create a Custom Skill

Next, define a custom Web API skill to extract date information from file names. This skill will be used to transform data during the indexing process.


{
  "@odata.type": "#Microsoft.Skills.Custom.WebApiSkill",
  "name": "parseDateSkill",
  "description": "A custom skill that parses dates from file names",
  "context": "/document",
  "uri": "https://yourfunctionapp.azurewebsites.net/api/parseDate",
  "httpMethod": "POST",
  "timeout": "PT30S",
  "batchSize": 1,
  "inputs": [
    {
      "name": "fileName",
      "source": "/document/content"
    }
  ],
  "outputs": [
    {
      "name": "parsedDate",
      "targetName": "parsedDate"
    }
  ]
}

This JSON snippet defines a Web API skill that sends data to a specified endpoint, which you must implement in an Azure Function App to parse dates.

Step 3: Implement the Azure Function

Implement the function in Azure Functions to handle requests from the custom skill. The function should parse dates from file names and return them in the expected format.


import datetime
import azure.functions as func
import logging

app = func.FunctionApp()

@app.function_name(name="parse_date")
@app.route(route="api/parseDate", methods=["POST"])
def parse_date(req: func.HttpRequest) -> func.HttpResponse:
    try:
        req_body = req.get_json()
        file_name = req_body.get('fileName')
        # Extract date from file name
        parsed_date = extract_date_from_filename(file_name)
        if parsed_date:
            return func.HttpResponse(body={"parsedDate": parsed_date.isoformat()}, status_code=200)
        else:
            return func.HttpResponse(status_code=204)
    except Exception as e:
        logging.error(f"Error parsing date: {e}")
        return func.HttpResponse(status_code=500)

def extract_date_from_filename(file_name):
    # Logic to extract date from file name
    try:
        date_str = file_name.split('_')[1]  # Example: 'file_20260101.txt'
        return datetime.datetime.strptime(date_str, "%Y%m%d")
    except (IndexError, ValueError):
        return None

Deploy this function to Azure, ensuring it is accessible from the Web API URI specified in the custom skill.

Step 4: Configure the Skillset

In your Azure Cognitive Search service, configure the skillset to include your custom skill.


{
  "name": "my-skillset",
  "skills": [
    {
      "@odata.type": "#Microsoft.Skills.Text.EntityRecognitionSkill",
      "name": "recognizeEntities",
      "description": "Recognize entities",
      "context": "/document/content",
      "defaultLanguageCode": "en",
      "inputs": [
        {"name": "text", "source": "/document/content"}
      ],
      "outputs": [
        {"name": "entities", "targetName": "recognizedEntities"}
      ]
    },
    {
      "@odata.type": "#Microsoft.Skills.Custom.WebApiSkill",
      "name": "parseDateSkill",
      "description": "Parse dates from file names",
      "context": "/document",
      "uri": "https://yourfunctionapp.azurewebsites.net/api/parseDate",
      "httpMethod": "POST",
      "timeout": "PT30S",
      "batchSize": 1,
      "inputs": [
        {
          "name": "fileName",
          "source": "/document/content"
        }
      ],
      "outputs": [
        {
          "name": "parsedDate",
          "targetName": "parsedDate"
        }
      ]
    }
  ]
}

Ensure the skillset is associated with your Azure Search Index.

Step 5: Set Up the Indexer

Finally, configure the indexer to apply the skillset to your data source.


{
  "name": "my-indexer",
  "dataSourceName": "my-datasource",
  "targetIndexName": "my-index",
  "skillsetName": "my-skillset",
  "parameters": {
    "configuration": {
      "dataToExtract": "contentAndMetadata"
    }
  },
  "fieldMappings": [
    {
      "sourceFieldName": "metadata_storage_path",
      "targetFieldName": "content"
    }
  ],
  "outputFieldMappings": [
    {
      "sourceFieldName": "/document/parsedDate",
      "targetFieldName": "parsedDate"
    }
  ]
}

Run the indexer to start populating your index.

Common Errors/Troubleshooting

  • Null Values in ParsedDate: Ensure the parsing logic in your function correctly extracts and formats dates. Verify that the Web API skill URI is correct and accessible.
  • Function App Errors: Check the Azure Function logs for any errors during execution. Ensure the function is correctly deployed and receives expected input.
  • Indexer Configuration Issues: Verify that the field mappings and skillset configurations are correctly applied. Incorrect mappings can lead to unpopulated fields.

Frequently Asked Questions

Why is my ParsedDate field null?

Check your function logic and ensure the skillset is correctly configured. Confirm that your function app is accessible and returning valid dates.

How do I test my Azure Function?

Use tools like Postman to send HTTP requests to your function endpoint, simulating the data sent by the Azure skill.

Can I use other languages for the function?

Yes, Azure Functions supports multiple languages, including JavaScript, C#, and Java. Choose the one you are most comfortable with.

Frequently Asked Questions

Why is my ParsedDate field null?

Check your function logic and ensure the skillset is correctly configured. Confirm that your function app is accessible and returning valid dates.

How do I test my Azure Function?

Use tools like Postman to send HTTP requests to your function endpoint, simulating the data sent by the Azure skill.

Can I use other languages for the function?

Yes, Azure Functions supports multiple languages, including JavaScript, C#, and Java. Choose the one you are most comfortable with.