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

喜你入骨 提交于 2020-01-17 13:46:13

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/39640608/what-is-the-supported-model-for-multi-level-document-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!