Copy data to an Azure AI Search index using Azure Data Factory or Synapse Analytics

APPLIES TO: Azure Data Factory Azure Synapse Analytics

Tip

Try out Data Factory in Microsoft Fabric, an all-in-one analytics solution for enterprises. Microsoft Fabric covers everything from data movement to data science, real-time analytics, business intelligence, and reporting. Learn how to start a new trial for free!

This article outlines how to use the Copy Activity in an Azure Data Factory or Synapse Analytics pipeline to copy data into Azure AI Search index. It builds on the copy activity overview article that presents a general overview of copy activity.

Supported capabilities

This Azure AI Search connector is supported for the following capabilities:

Supported capabilities IR Managed private endpoint
Copy activity (-/sink) ① ②

① Azure integration runtime ② Self-hosted integration runtime

You can copy data from any supported source data store into search index. For a list of data stores that are supported as sources/sinks by the copy activity, see the Supported data stores table.

Getting started

To perform the Copy activity with a pipeline, you can use one of the following tools or SDKs:

Create a linked service to Azure Search using UI

Use the following steps to create a linked service to Azure Search in the Azure portal UI.

  1. Browse to the Manage tab in your Azure Data Factory or Synapse workspace and select Linked Services, then click New:

  2. Search for Search and select the Azure Search connector.

    Select the Azure Search connector.

  3. Configure the service details, test the connection, and create the new linked service.

    Configure a linked service to Azure Search.

Connector configuration details

The following sections provide details about properties that are used to define Data Factory entities specific to Azure AI Search connector.

Linked service properties

The following properties are supported for Azure AI Search linked service:

Property Description Required
type The type property must be set to: AzureSearch Yes
url URL for the search service. Yes
key Admin key for the search service. Mark this field as a SecureString to store it securely, or reference a secret stored in Azure Key Vault. Yes
connectVia The Integration Runtime to be used to connect to the data store. You can use Azure Integration Runtime or Self-hosted Integration Runtime (if your data store is located in private network). If not specified, it uses the default Azure Integration Runtime. No

Important

When copying data from a cloud data store into search index, in Azure AI Search linked service, you need to refer an Azure Integration Runtime with explicit region in connactVia. Set the region as the one where your search service resides. Learn more from Azure Integration Runtime.

Example:

{
    "name": "AzureSearchLinkedService",
    "properties": {
        "type": "AzureSearch",
        "typeProperties": {
            "url": "https://<service>.search.windows.net",
            "key": {
                "type": "SecureString",
                "value": "<AdminKey>"
            }
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

Dataset properties

For a full list of sections and properties available for defining datasets, see the datasets article. This section provides a list of properties supported by Azure AI Search dataset.

To copy data into Azure AI Search, the following properties are supported:

Property Description Required
type The type property of the dataset must be set to: AzureSearchIndex Yes
indexName Name of the search index. The service does not create the index. The index must exist in Azure AI Search. Yes

Example:

{
    "name": "AzureSearchIndexDataset",
    "properties": {
        "type": "AzureSearchIndex",
        "typeProperties" : {
            "indexName": "products"
        },
        "schema": [],
        "linkedServiceName": {
            "referenceName": "<Azure AI Search linked service name>",
            "type": "LinkedServiceReference"
        }
   }
}

Copy activity properties

For a full list of sections and properties available for defining activities, see the Pipelines article. This section provides a list of properties supported by Azure AI Search source.

Azure AI Search as sink

To copy data into Azure AI Search, set the source type in the copy activity to AzureSearchIndexSink. The following properties are supported in the copy activity sink section:

Property Description Required
type The type property of the copy activity source must be set to: AzureSearchIndexSink Yes
writeBehavior Specifies whether to merge or replace when a document already exists in the index. See the WriteBehavior property.

Allowed values are: Merge (default), and Upload.
No
writeBatchSize Uploads data into the search index when the buffer size reaches writeBatchSize. See the WriteBatchSize property for details.

Allowed values are: integer 1 to 1,000; default is 1000.
No
maxConcurrentConnections The upper limit of concurrent connections established to the data store during the activity run. Specify a value only when you want to limit concurrent connections. No

WriteBehavior property

AzureSearchSink upserts when writing data. In other words, when writing a document, if the document key already exists in the search index, Azure AI Search updates the existing document rather than throwing a conflict exception.

The AzureSearchSink provides the following two upsert behaviors (by using AzureSearch SDK):

  • Merge: combine all the columns in the new document with the existing one. For columns with null value in the new document, the value in the existing one is preserved.
  • Upload: The new document replaces the existing one. For columns not specified in the new document, the value is set to null whether there is a non-null value in the existing document or not.

The default behavior is Merge.

WriteBatchSize Property

Azure AI Search service supports writing documents as a batch. A batch can contain 1 to 1,000 Actions. An action handles one document to perform the upload/merge operation.

Example:

"activities":[
    {
        "name": "CopyToAzureSearch",
        "type": "Copy",
        "inputs": [
            {
                "referenceName": "<input dataset name>",
                "type": "DatasetReference"
            }
        ],
        "outputs": [
            {
                "referenceName": "<Azure AI Search output dataset name>",
                "type": "DatasetReference"
            }
        ],
        "typeProperties": {
            "source": {
                "type": "<source type>"
            },
            "sink": {
                "type": "AzureSearchIndexSink",
                "writeBehavior": "Merge"
            }
        }
    }
]

Data type support

The following table specifies whether an Azure AI Search data type is supported or not.

Azure AI Search data type Supported in Azure AI Search Sink
String Y
Int32 Y
Int64 Y
Double Y
Boolean Y
DataTimeOffset Y
String Array N
GeographyPoint N

Currently other data types e.g. ComplexType are not supported. For a full list of Azure AI Search supported data types, see Supported data types (Azure AI Search).

For a list of data stores supported as sources and sinks by the copy activity, see supported data stores.