How to Index on Specific document Library from the Sharepoint Subsite in Azure Cognitive Search

Marcelo Lorenzetti 20 Reputation points
2025-03-21T12:43:07.1+00:00

below is the Full Url of the Document library:
https://test.sharepoint.com/sites/Corporate-Technology/sandbox/azuresearchtest/Forms/AllItems.aspx

Site : Corporate-Technology
Subsite : sandbox
Document Library : azuresearchtest

Below API use to create DataSourse

curl --location 'https://test.search.windows.net/datasources?api-version=2020-06-30' \
--header 'api-key: aVL4MqPqtAoRQc28aQoGSymu1SM8ioxtGl8HFUvAUVAzSeCj8Ypf' \
--header 'Content-Type: application/json' \
--data '{
    "name": "sharepoint-search1",
    "type": "sharepoint",
    "credentials": {
        "connectionString": "SharePointOnlineEndpoint=https://test.sharepoint.com/sites/Corporate-Technology/sandbox/;ApplicationId=270d755b-3fa8-4436-b90a-1f69b920c3de"
    },
    "container": {
        "name": "azuresearchtest",
        "query": null
    }
}'

Response of the Above API :

{
    "error": {
        "code": "",
        "message": "Container name azuresearchtest is invalid for type sharepoint."
    }
}

how to create datasource for specific Document Library.In my case Document library is "azuresearchtest"

Thank you

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,279 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Marcelo Lorenzetti 20 Reputation points
    2025-03-24T04:55:21.76+00:00

    When using created resoure to create Indexer ,
    curl --location 'https://test.search.windows.net/indexers?api-version=2024-05-01-preview' \

    --header 'api-key: aVL4MqPqtAoQQc28aQoGSymu1SM8ioxtGl8HFUvAUVAzSeCj8Ypf' \

    --header 'Content-Type: application/json' \

    --data '{

    "name": "sharepoint-indexer1",
    
    "dataSourceName": "sharepoint-search",
    
    "targetIndexName": "sharepoint-index",
    
    "parameters": {
    
        "batchSize": null,
    
        "maxFailedItems": null,
    
        "maxFailedItemsPerBatch": null,
    
        "base64EncodeKeys": null,
    
        "configuration": {
    
            "indexedFileNameExtensions": ".pdf, .docx",
    
            "excludedFileNameExtensions": ".png, .jpg",
    
            "dataToExtract": "contentAndMetadata"
    
        }
    
    },
    
    "schedule": {},
    
    "outputFieldMappings": [
    
        {
    
            "sourceFieldName": "/document/content/myKeyPhrases",
    
            "targetFieldName": "content"
    
        }
    
    ],
    
    "fieldMappings": [
    
        {
    
            "sourceFieldName": "metadata_spo_site_library_item_id",
    
            "targetFieldName": "id",
    
            "mappingFunction": {
    
                "name": "base64Encode"
    
            }
    
        }
    
    ]
    

    }'

    Error :

    {
        "error": {
            "code": "",
            "message": "Error with data source: Unexpected keyword 'p' in query property.  Please adjust your data source definition in order to proceed."
        }
    }
    
    0 comments No comments

  2. Bodapati Harish 320 Reputation points Microsoft External Staff
    2025-03-25T09:13:57.72+00:00

    Hello @Marcelo Lorenzetti,

    The error occurs due to an incorrect query format in the data source definition. The container.name should be "useQuery", and the query parameter must correctly point to the document library path.

    • Modify the data source creation request to correctly target the document library:
    
    curl --location 'https://test.search.windows.net/datasources?api-version=2020-06-30' \
    
    --header 'api-key: aVL4MqPqtAoRQc28aQoGSymu1SM8ioxtGl8HFUvAUVAzSeCj8Ypf' \
    
    --header 'Content-Type: application/json' \
    
    --data '{
    
        "name": "sharepoint-search1",
    
        "type": "sharepoint",
    
        "credentials": {
    
            "connectionString": "SharePointOnlineEndpoint=https://test.sharepoint.com/sites/Corporate-Technology/sandbox/;ApplicationId=270d755b-3fa8-4436-b90a-1f69b920c3de"
    
        },
    
        "container": {
    
            "name": "useQuery",
    
            "query": "path:\"https://test.sharepoint.com/sites/Corporate-Technology/sandbox/azuresearchtest\""
    
        }
    
    }'
    
    
    • Update the indexer request to use the corrected data source:
    
    curl --location 'https://test.search.windows.net/indexers?api-version=2024-05-01-preview' \
    
    --header 'api-key: aVL4MqPqtAoQQc28aQoGSymu1SM8ioxtGl8HFUvAUVAzSeCj8Ypf' \
    
    --header 'Content-Type: application/json' \
    
    --data '{
    
        "name": "sharepoint-indexer1",
    
        "dataSourceName": "sharepoint-search1",
    
        "targetIndexName": "sharepoint-index",
    
        "parameters": {
    
            "batchSize": null,
    
            "maxFailedItems": null,
    
            "maxFailedItemsPerBatch": null,
    
            "base64EncodeKeys": null,
    
            "configuration": {
    
                "indexedFileNameExtensions": ".pdf, .docx",
    
                "excludedFileNameExtensions": ".png, .jpg",
    
                "dataToExtract": "contentAndMetadata"
    
            }
    
        },
    
        "schedule": {},
    
        "outputFieldMappings": [
    
            {
    
                "sourceFieldName": "/document/content/myKeyPhrases",
    
                "targetFieldName": "content"
    
            }
    
        ],
    
        "fieldMappings": [
    
            {
    
                "sourceFieldName": "metadata_spo_site_library_item_id",
    
                "targetFieldName": "id",
    
                "mappingFunction": {
    
                    "name": "base64Encode"
    
                }
    
            }
    
        ]
    
    }'
    
    • If the issue persists try using a different API version, such as 2020-06-30 or 2024-05-01-preview. Verify that your SharePoint Application ID has the necessary permissions to access the document library.

    Hope this help!


    Please do not forget to click "Accept the answer” and Yes wherever the information provided helps you, this can be beneficial to other community members.

    User's image

    If you have any other questions or still running into more issues, let me know in the "comments" and I would be happy to help you.


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.