Using .net/c# to run the cognitive search indexer

Matt Dorsey 151 Reputation points
2022-07-13T15:32:26.217+00:00

I've got a web application that allows users to regularly upload documents into an azure blob container. After upload I then run the Azure indexer service to make the documents available to search through. I'd like to automate the process of running the indexer after the user uploads their documents. I've started to develop this azure function using a blob trigger, but I'm having a difficult time coming up with the code to begin running the indexer... Is there an example I can look at?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,930 questions
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,351 questions
0 comments No comments
{count} votes

Accepted answer
  1. MayankBargali-MSFT 70,941 Reputation points Moderator
    2022-07-14T06:40:34.607+00:00

    @Matt Dorsey Thanks for reaching out. You can execute run indexer REST API as you do in any of your C# code. To get more familiar with Cognitive Search Service REST you can refer to this document. Sharing a few references on how to call any service but you need to update the header/build the request as per the run indexer document.
    https://stackoverflow.com/questions/56288606/best-approach-to-call-web-api-from-azure-function
    https://learn.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,506 Reputation points
    2022-07-14T06:42:27.367+00:00

    Hi @Matt Dorsey ,

    Thanks for reaching out to Q&A forum.

    According to Azure cognitive search documentation, you can configure and run the indexer on the blob files in the container via Rest API calls

    POST https://[service name].search.windows.net/indexers?api-version=2020-06-30
    {
    "name" : "my-blob-indexer,
    "dataSourceName" : "my-blob-datasource",
    "targetIndexName" : "my-search-index",
    "parameters": {
    "batchSize": null,
    "maxFailedItems": null,
    "maxFailedItemsPerBatch": null,
    "base64EncodeKeys": null,
    "configuration:" {
    "indexedFileNameExtensions" : ".pdf,.docx",
    "excludedFileNameExtensions" : ".png,.jpeg",
    "dataToExtract": "contentAndMetadata",
    "parsingMode": "default"
    }
    },
    "schedule" : { },
    "fieldMappings" : [ ]
    }

    You can make Rest API calls using Httpclient in C#. This can be implemented in .net based function app.

    I hope this helps! Feel free to reach out to me if you have further queries or concerns.

    1 person found this answer helpful.
    0 comments No comments

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.