Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

azure - what is the supported Model for multi-level Document search?

I have created few documents in DocumentDb and i am looking for how to search multi-level or parent child objects in single document using Azure search services.

can you any one help me out/any links.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Azure Search requires documents to be flattened, so what you will need to do is create a query in DocumentDB to help you do this. To get started, there is a document here, that will give you some information on how to model these more complex data types in Azure Search.

Also, I prefer to do this flattening right in DocumentDB. To do this, User Defined Functions (UDF) are a great way to do this. Here is an example that allows you to pass in an Array and take all the items of type "child" and pass it back as an Array.

function convertToArray (data, child) { 
    var resultArray = [];
    for (var i = 0; i < data.length; i++)
    {
        resultArray.push(data[i][child]); 
    }

    return resultArray;
}

Then within DocumentDB, you would do a query something like this:

SELECT 
c.userName, 
udf.convertToArray(c.addresses, "city") as City
FROM c

So if c.addresses looked like this:

[
    {
      "city": "Toronto",
      "country": "Canada"
    },
    {
      "city": "Seattle",
      "country": "USA"
    }
  ]

The output from the UDF would be:

["Toronto", "Seattle"]

which can then be loaded into the Azure Search in an Collection datatype.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...