Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...