Exclude File Name with extension in Azure Search .net sdk

351 views Asked by At

I have written a .net sdk to create index and Indexer. How i Exclude some files from indexing based on the extension. I am not able to find sample/example to do the same

    Indexer indexer = new Indexer()
        {
            Name = indexerName,
            DataSourceName = userDocsDataSource,
            TargetIndexName = indexName,
            Schedule = new IndexingSchedule()
            {
                Interval = System.TimeSpan.FromMinutes(Convert.ToDouble(ConfigurationManager.AppSettings["indexrefreshtime"]))
            }
        };

Please let me know. Thanks

1

There are 1 answers

0
Gaurav Mantri On

Please try something like the following:

    Indexer indexer = new Indexer()
    {
        Name = indexerName,
        DataSourceName = userDocsDataSource,
        TargetIndexName = indexName,
        Parameters = new IndexingParameters(),
        Schedule = new IndexingSchedule()
        {
            Interval = System.TimeSpan.FromMinutes(Convert.ToDouble(ConfigurationManager.AppSettings["indexrefreshtime"]))
        }
    };
    indexer.Parameters.ExcludeFileNameExtensions(".pdf", ".doc");

You can read documentation about Client SDK here: https://learn.microsoft.com/en-us/dotnet/api/overview/azure/search/client?view=azure-dotnet.