Copy data to an Azure Search index using Azure Data Factory

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

Note

This article applies to version 2 of Data Factory, which is currently in preview. If you are using version 1 of the Data Factory service, which is generally available (GA), see Azure Search connector in V1.

Supported capabilities

You can copy data from any supported source data store into Azure 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

You can create a pipeline with copy activity by using one of the following tools/SDKs: Click a link to navigate to a tutorial with step-by-step instructions to create a pipeline with a copy activity.

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

Linked service properties

The following properties are supported for Azure Search linked service:

Property Description Required
type The type property must be set to: AzureSearch Yes
url URL for the Azure Search service. Yes
key Admin key for the Azure Search service. Mark this field as a SecureString to store it securely in Data Factory, 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 Azure Search index, in Azure Search linked service, you need to refer a Azure Integration Runtime with explicit region in connactVia. Set the region as the one your Azure Search 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 Search dataset.

To copy data into Azure Search, set the type property of the dataset to RelationalTable. 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 Azure Search index. Data Factory does not create the index. The index must exist in Azure Search. Yes

Example:

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

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 Search source.

Azure Search as sink

To copy data into Azure 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 Azure 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

WriteBehavior property

AzureSearchSink upserts when writing data. In other words, when writing a document, if the document key already exists in the Azure Search index, Azure 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 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 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 Search data type is supported or not.

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

Next steps

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