Skip to content

Commit 86e4918

Browse files
Merge pull request #263896 from arv100kri/to-json
Add toJson field mapping function
2 parents 3789b4e + 7dafee8 commit 86e4918

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

articles/search/search-indexer-field-mappings.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,48 @@ When errors occur that are related to document key length exceeding 1024 charact
378378
]
379379
```
380380

381+
<a name="toJsonFunction"></a>
382+
383+
### toJson function
384+
385+
This function converts a string into a formatted JSON object. This can be used for scenarios where the data source, such as Azure SQL, doesn't natively support compound or hierarchical data types, and then map it to complex fields.
386+
387+
### Example - map text content to a complex field
388+
389+
Assume there is a SQL row with a JSON string that needs to be mapped to a (correspondingly defined) complex field in the index, the `toJson` function can be used to achieve this. For instance, if a complex field in the index needs to be populated with the following data:
390+
391+
```JSON
392+
{
393+
"id": "5",
394+
"info": {
395+
"name": "Jane",
396+
"surname": "Smith",
397+
"skills": [
398+
"SQL",
399+
"C#",
400+
"Azure"
401+
],
402+
"dob": "2005-11-04T12:00:00"
403+
}
404+
}
405+
```
406+
It can be achieved by using the `toJson` mapping function on a JSON string column in a SQL row that looks like this: `{"id": 5, "info": {"name": "Jane", "surname": "Smith", "skills": ["SQL", "C#", "Azure"]}, "dob": "2005-11-04T12:00:00"}`.
407+
408+
The field mapping needs to be specified as shown below.
409+
410+
```JSON
411+
412+
"fieldMappings" : [
413+
{
414+
"sourceFieldName" : "content",
415+
"targetFieldName" : "complexField",
416+
"mappingFunction" : {
417+
"name" : "toJson"
418+
}
419+
}
420+
]
421+
```
422+
381423
## See also
382424

383425
+ [Supported data types in Azure AI Search](/rest/api/searchservice/supported-data-types)

0 commit comments

Comments
 (0)