You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/search/search-indexer-field-mappings.md
+44-22Lines changed: 44 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,8 +10,8 @@ ms.author: heidist
10
10
ms.service: cognitive-search
11
11
ms.custom:
12
12
- ignite-2023
13
-
ms.topic: conceptual
14
-
ms.date: 06/25/2024
13
+
ms.topic: how-to
14
+
ms.date: 07/29/2024
15
15
---
16
16
17
17
# Field mappings and transformations using Azure AI Search indexers
@@ -24,7 +24,9 @@ Field mappings can also be used for light-weight data conversions, such as encod
24
24
25
25
Field mappings apply to:
26
26
27
-
+ Physical data structures on both sides of the data stream (between fields in a [supported data source](search-indexer-overview.md#supported-data-sources) and fields in a [search index](search-what-is-an-index.md)). If you're importing skill-enriched content that resides in memory, use [outputFieldMappings](cognitive-search-output-field-mapping.md) to map in-memory nodes to output fields in a search index.
27
+
+ Physical data structures on both sides of the data stream (between fields in a [supported data source](search-indexer-overview.md#supported-data-sources) and fields in a [search index](search-what-is-an-index.md)).
28
+
29
+
If you're importing skill-generated content that resides in memory, use [outputFieldMappings](cognitive-search-output-field-mapping.md) to map in-memory nodes to output fields in a search index.
28
30
29
31
+ Search indexes only. If you're populating a [knowledge store](knowledge-store-concept-intro.md), use [projections](knowledge-store-projections-examples.md) for data path configuration.
30
32
@@ -45,17 +47,37 @@ Field mappings apply to:
45
47
46
48
## Define a field mapping
47
49
48
-
Field mappings are added to the `fieldMappings` array of an indexer definition. A field mapping consists of three parts.
50
+
This section explains how to set up field mappings.
49
51
50
-
```json
51
-
"fieldMappings": [
52
-
{
53
-
"sourceFieldName": "_city",
54
-
"targetFieldName": "city",
55
-
"mappingFunction": null
56
-
}
57
-
]
58
-
```
52
+
### [**REST APIs**](#tab/rest)
53
+
54
+
1. Use [Create Indexer](/rest/api/searchservice/indexers/create) or [Create or Update Indexer](/rest/api/searchservice/indexers/create-or-update) or an equivalent method in an Azure SDK. Here's an example of an indexer definition.
55
+
56
+
```json
57
+
{
58
+
"name": "myindexer",
59
+
"description": null,
60
+
"dataSourceName": "mydatasource",
61
+
"targetIndexName": "myindex",
62
+
"schedule": { },
63
+
"parameters": { },
64
+
"fieldMappings": [],
65
+
"disabled": false,
66
+
"encryptionKey": { }
67
+
}
68
+
```
69
+
70
+
1. Fill out the `fieldMappings` array to specify the mappings. A field mapping consists of three parts.
71
+
72
+
```json
73
+
"fieldMappings": [
74
+
{
75
+
"sourceFieldName": "_city",
76
+
"targetFieldName": "city",
77
+
"mappingFunction": null
78
+
}
79
+
]
80
+
```
59
81
60
82
| Property | Description |
61
83
|----------|-------------|
@@ -70,13 +92,9 @@ Azure AI Search uses case-insensitive comparison to resolve the field and functi
70
92
> [!NOTE]
71
93
> If no field mappings are present, indexers assume data source fields should be mapped to index fields with the same name. Adding a field mapping overrides the default field mappings for the source and target field. Some indexers, such as the [blob storage indexer](search-howto-indexing-azure-blob-storage.md), add default field mappings for the index key field.
72
94
73
-
You can use the REST API or an Azure SDK to define field mappings.
74
-
75
-
### [**REST APIs**](#tab/rest)
76
-
77
-
Use [Create Indexer (REST)](/rest/api/searchservice/indexers/create) or [Update Indexer (REST)](/rest/api/searchservice/indexers/create-or-update), any API version.
95
+
#### Example: Name or type discrepancy
78
96
79
-
This example handles a field name discrepancy.
97
+
An explicit field mapping establishes a data path for cases where name and type aren't identical.
80
98
81
99
```JSON
82
100
PUT https://[service name].search.windows.net/indexers/myindexer?api-version=[api-version]
@@ -89,6 +107,8 @@ api-key: [admin key]
89
107
}
90
108
```
91
109
110
+
#### Example: One-to-many or forked data paths
111
+
92
112
This example maps a single source field to multiple target fields ("one-to-many" mappings). You can "fork" a field, copying the same source field content to two different index fields that will be analyzed or attributed differently in the index.
93
113
94
114
```JSON
@@ -99,6 +119,8 @@ This example maps a single source field to multiple target fields ("one-to-many"
99
119
]
100
120
```
101
121
122
+
You can use a similar approach for [skills-generated content](cognitive-search-output-field-mapping.md).
123
+
102
124
### [**.NET SDK (C#)**](#tab/csharp)
103
125
104
126
In the Azure SDK for .NET, use the [FieldMapping](/dotnet/api/azure.search.documents.indexes.models.fieldmapping) class that provides `SourceFieldName` and `TargetFieldName` properties and an optional `MappingFunction` reference.
@@ -136,11 +158,11 @@ A field mapping function transforms the contents of a field before it's stored i
136
158
+[urlEncode](#urlEncodeFunction)
137
159
+[urlDecode](#urlDecodeFunction)
138
160
139
-
Note that these functions are exclusively supported for parent indexes at this time. They are not compatible with chunked index mapping, therefore, these functions can't be used for [index projections](index-projections-concept-intro.md).
161
+
Note that these functions are exclusively supported for parent indexes at this time. They aren't compatible with chunked index mapping, therefore, these functions can't be used for [index projections](index-projections-concept-intro.md).
140
162
141
163
<aname="base64EncodeFunction"></a>
142
164
143
-
### base64Encode function
165
+
### base64Encode function and examples
144
166
145
167
Performs *URL-safe* Base64 encoding of the input string. Assumes that the input is UTF-8 encoded.
146
168
@@ -301,7 +323,7 @@ For example, if the input string is `["red", "white", "blue"]`, then the target
301
323
302
324
#### Example - populate collection from relational data
303
325
304
-
Azure SQL Database doesn't have a built-in data type that naturally maps to `Collection(Edm.String)` fields in Azure AI Search. To populate string collection fields, you can pre-process your source data as a JSON string array and then use the `jsonArrayToStringCollection` mapping function.
326
+
Azure SQL Database doesn't have a built-in data type that naturally maps to `Collection(Edm.String)` fields in Azure AI Search. To populate string collection fields, you can preprocess your source data as a JSON string array and then use the `jsonArrayToStringCollection` mapping function.
0 commit comments