Search code examples
azuresql-viewazure-cognitive-search

Create Collection in Azure Search Service Using View


I'm trying to create index which using import data tool.

The datasource is from azure sql's view.

SELECT
b.Name,
b.ID
(SELECT
'[' + STUFF((
    SELECT
        ',{"name":"' + p.Name + '"}'
    FROM Product p WHERE p.Brand = b.ID
    FOR XML PATH (''), TYPE)
.value('.', 'nvarchar(max)'), 1, 1, '') + ']') AS TAry, 
b.IsDelete,
b.ModifyDatetime
from Brand b

Column with TAry will return JSon format string like: [{"name":"Test1"},{"name":"Test2"}]

In Indexder properties with field TAry Chose the type Collection(Edm.String)

After create , It's return error , the message below:

"The data field 'TAry' has an invalid value. The expected type was 'Collection(Edm.String)'."

Thank for your reply.

I have try this kind format :[Test1","Test2"] still not work.


Solution

  • To do this, you need to use Azure Search REST API to set up a field mapping with jsonArrayToStringCollection function. Take a look at this article for detailed instructions.