Index a specific SharePoint library in Azure AI Search
Follow this post to set up Azure AI Search with SharePoint as a datasource, including how to target a specific library rather than only the default document library.
SharePoint datasource container options
Azure AI Search supports three container modes for SharePoint sources:
| Value | Description |
|---|---|
defaultSiteLibrary | Indexes only the site’s default document library (usually Documents). |
allSiteLibraries | Indexes all document libraries in the site. Does not automatically include subsites. |
useQuery | Lets you explicitly specify which libraries or sites to include/exclude using the query property. |
Common useQuery keywords
includeLibrariesInSiteincludeLibraryexcludeLibraryadditionalColumns
Example: default library only
{
"name": "sharepoint-datasource",
"type": "sharepoint",
"credentials": {
"connectionString": "SharePointOnlineEndpoint={{SharePoint Site URL}};ApplicationId={{App Registration Client ID}};FederatedCredentialObjectId={{Managed Identity Object ID}};TenantId={{Tenant ID}};"
},
"container": {
"name": "defaultSiteLibrary",
"query": null
}
}
Example: target a specific library
To index a specific library, set the container name to useQuery and provide the library URL in the query value.
{
"name": "sharepoint-datasource",
"type": "sharepoint",
"credentials": {
"connectionString": "SharePointOnlineEndpoint={{SharePoint Site URL}};ApplicationId={{App Registration Client ID}};FederatedCredentialObjectId={{Managed Identity Object ID}};TenantId={{Tenant ID}};"
},
"container": {
"name": "useQuery",
"query": "includeLibrary=https://contoso.sharepoint.com/sites/AgentsToolkit/test/Forms/AllItems.aspx"
}
}
Example: All libraries in site
To index all libraries in a site, set the container name to useQuery and provide the site URL in the query value.
{
"name": "sharepoint-datasource",
"type": "sharepoint",
"credentials": {
"connectionString": "SharePointOnlineEndpoint={{SharePoint Site URL}};ApplicationId={{App Registration Client ID}};FederatedCredentialObjectId={{Managed Identity Object ID}};TenantId={{Tenant ID}};"
},
"container": {
"name": "useQuery",
"query": "includeLibrariesInSite=https://mycompany.sharepoint.com/sites/TopSite/SubSite1;includeLibrariesInSite=https://mycompany.sharepoint.com/sites/TopSite/SubSite2"
}
}
References
- How to index SharePoint content using Azure AI Search for Copilot agents
- Index data from SharePoint document libraries
- Configure Azure AI Search to index SharePoint
- Azure Cognitive Search: SharePoint Online indexer