Enabling Search Engine on Cosmos Graph Database

Enabling Search Engine on Cosmos Graph DatabaseAbhishekBlockedUnblockFollowFollowingDec 10IntroductionWhen you work with social graph, enterprise wide graph or document graph, Search Engine on top of graph database can help you design next generation enterprise grade solution .With indexed data in Search Engine and connected relationship in property Graph you can leverage best of both services.You would have noticed this with platform like Google, Facebook or Twitter etc..which uses search engine on top of graph database to provide better user experience in terms of navigation(list someone friend) or wildcard search .In this article we will take example of fictitious shop BarberShopInc a leverage Cosmos and leverage cosmos Graph database and Azure Search to perform full text search and then use gremlin.net to transverse through connected node..In this article we will also list down some of the key consideration which need to be taken care of when you start working with cosmos graph database and azure search.Solution Design- Using Gremlin.net with FunctionsThe solution consists of using Azure functions and gremlin.net to perform basic CRUD operation on cosmos graph database..We have modelled node for user (customer and employee) and organization (BarberShopInc) and set of edges as employee-of and customer-of as relationshipSample create User Vertices FunctionsThe sample gremlin query to add vertices of type customer can be tested through graph data explorer:Next step is to create BarberShopInc and employee vertices within the graph and create appropriate edge between the verticesCreating edges or relationship with gremlin is easy and require you the source identifier, target identifier and edge property which we can say as relationship .Identifier can be vertex id or any property which uniquely identify the vertices..In this case we have used sample function within function app to act as generic method for creating relationship.Edges within the graph are stored as typed JSON properties with following structure where inV determines incoming vertices and outV determines outgoing verticesNote: While designing graph structure always have a consistent approach for outgoing and incoming edges (prefer query on outgoing relationship).In the below screenshot you can see how we have organized outgoing edges within the subgraph structure Organization — -Out — -Employee — -Out — -CustomerNow by using serverless azure functions you can perfrom multiple query like finding verticesById ,GetVerticesbyType , GetoutgoingVertcies etc .Some of functions to get started with is listed belowEnable Azure Search Engine Cosmos Graph DatabaseIn this section we will enable Azure search for graph database..Enabling search on cosmos graph is simple and only requires you to copy the cosmos graph db connection string and setting up index property in azure search along with cognitive settings.For this solution purpose we have created instance of azure search called wikkisearch001 within appropriate resource groupNext step is to import the data from cosmos graph database collection into azure search..For this click on the import blade and select cosmosDB as data source and paste the cosmos DB connection string.In the next part you can enable cognitive search option on the cosmos graph data sourceLast section to this of this setup is to configure searchable properties on the data .For this sample purpose we will set all the properties to be searchable..You can always update the index at later stage based on your application requirementWhile choosing schedule always select once because good option is to use cosmos db change feed to update azure search indexOnce done click on Ok to complete the import step, you can verify the import configuration from Azure search home page which will list you the number of document imported from graph DB ..To test the azure search feature from portal, you can navigate to search toolbox and query on specific textConclusionWhen building real time web application like BarberShopInc with customer search capability, it is good choice to enable search on cosmos graph and use cosmos graph change feed to update search index data.Azure search can help you to enrich you web application and you get use azure search result to transverse through cosmos graph database node relationship.. More details

Leave a Reply