Search Graph Database
Search a Neo4j® graph database using functions provided by the MATLAB® interface to Neo4j and the Database Toolbox™ Interface for Neo4j Bolt Protocol. You can explore the graph data and perform graph network analysis using MATLAB directed graphs.
Search Functionality
Search graph data in a Neo4j graph database using different parts of the graph:
Search for one or more nodes using
searchNode
. Search for a node with a specific identifier usingsearchNodeByID
.Search for relationships from an origin node using
searchRelation
.Search for the entire graph database or a subgraph using
searchGraph
.
To access the part of the graph database that you want to analyze, combine these functions and explore the graph data in the output arguments.
General and Targeted Search Workflows
You can search a Neo4j graph database in a general or targeted way. A general search starts from a subgraph or the entire graph. A targeted search starts from an origin node and traverses its relationships.
After finding a part of the graph, you can create a MATLAB directed graph and perform graph network analysis.
Conduct General Search
Conduct a general search for a subgraph using
searchGraph
.For example, to find the subgraph
graphinfo
, enter this code, which assumes a successful Neo4j database connectionneo4jconn
. Thegraphinfo
output argument is a directed graph.nlabel = {'Person'}; graphinfo = searchGraph(neo4jconn,nlabel, ... 'DataReturnFormat','digraph');
Perform graph network analysis using the
digraph
objectG
. For details, see Directed and Undirected Graphs.For example, determine the shortest path between nodes using
distances
.d = distances(G);
Or, explore the graph data by executing the
searchGraph
function without the'DataReturnFormat'
name-value pair argument and accessing the output structuregraphinfo
.
Conduct Targeted Search
To start your search, find the origin node using
searchNode
orsearchNodeByID
.For example, to find the origin node
nodeinfo
, enter this code, which assumes a successful Neo4j database connectionneo4jconn
and the node identifier2
.nodeinfo = searchNodeByID(neo4jconn,2);
Search for graph data by using the origin node and
searchRelation
. Or, if you know the relationship identifier, then use thesearchRelationByID
function.For example, this code assumes that you are searching for incoming relationships. The
relinfo
output argument is a directed graph.relinfo = searchRelation(neo4jconn,nodeinfo,'in','DataReturnFormat','digraph');
Perform graph network analysis using the
digraph
objectG
. For details, see Directed and Undirected Graphs.For example, determine the shortest path between nodes using
distances
.d = distances(G);
Or, explore node information by accessing the output structure
nodeinfo
. Also, explore relationship information by executing thesearchRelation
function without the'DataReturnFormat'
name-value pair argument and accessing the output structurerelinfo
.
See Also
searchNode
| searchNodeByID
| searchRelation
| searchGraph
| nodeDegree
Related Topics
- Explore Graph Database Structure
- Find Shortest Path Between People in Social Neighborhood
- Graph Database Workflow for Neo4j Database Interfaces
- Error Messages for Neo4j Database Interfaces