Search relationships for Neo4j database node
returns relationship information for the origin node relinfo
= searchRelation(neo4jconn
,nodeinfo
,direction
)nodeinfo
and
relationship direction using a Neo4j® database connection. The search starts from the origin node. To find
an origin node, use searchNode
or searchNodeByID
.
Search for information about a relationship in a Neo4j® database and display the information.
Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name
with a value ranging from User1
through User7
. Each relationship has the type knows
.
Create a Neo4j database connection using the URL http://localhost:7474/db/data
, user name neo4j
, and password matlab
.
url = 'http://localhost:7474/db/data'; username = 'neo4j'; password = 'matlab'; neo4jconn = neo4j(url,username,password);
Check the Message
property of the Neo4j connection object neo4jconn
. The blank Message
property indicates a successful connection.
neo4jconn.Message
ans = []
Retrieve the origin node nodeinfo
using the Neo4j database connection and the node identifier 3
.
nodeid = 3; nodeinfo = searchNodeByID(neo4jconn,nodeid);
Search for incoming relationships using the Neo4j database connection and the origin node nodeinfo
.
direction = 'in';
relinfo = searchRelation(neo4jconn,nodeinfo,direction)
relinfo = struct with fields:
Origin: 3
Nodes: [2×3 table]
Relations: [1×5 table]
relinfo
is a structure that contains the results of the search:
Origin
— The node identifier for the specified origin node
Nodes
— A table containing all start and end nodes for each matched relationship
Relations
— A table containing all matched relationships
Access the table of nodes.
relinfo.Nodes
ans=2×3 table
NodeLabels NodeData NodeObject
__________ ____________ ___________________________________
1 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
3 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
Access the table of relationships.
relinfo.Relations
ans=1×5 table
StartNodeID RelationType EndNodeID RelationData RelationObject
___________ ____________ _________ ____________ _______________________________________
3 1 'knows' 3 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
Close the database connection.
close(neo4jconn)
Search for information about relationships in a Neo4j® database and display the information. Specify the relationship type and distance to search.
Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name
with a value ranging from User1
through User7
. Each relationship has the type knows
.
Create a Neo4j database connection using the URL http://localhost:7474/db/data
, user name neo4j
, and password matlab
.
url = 'http://localhost:7474/db/data'; username = 'neo4j'; password = 'matlab'; neo4jconn = neo4j(url,username,password);
Check the Message
property of the Neo4j connection object neo4jconn
. The blank Message
property indicates a successful connection.
neo4jconn.Message
ans = []
Retrieve the origin node nodeinfo
using the Neo4j database connection and the node identifier 3
.
nodeid = 3; nodeinfo = searchNodeByID(neo4jconn,nodeid);
Search for incoming relationships using the Neo4j database connection and the origin node nodeinfo
. Refine the search by filtering for the relationship type knows
and for nodes at a distance of two or fewer.
direction = 'in'; reltypes = {'knows'}; relinfo = searchRelation(neo4jconn,nodeinfo,direction, ... 'RelationTypes',reltypes,'Distance',2)
relinfo = struct with fields:
Origin: 3
Nodes: [4×3 table]
Relations: [3×5 table]
relinfo
is a structure that contains the results of the search:
Origin
— The node identifier for the specified origin node
Nodes
— A table containing all start and end nodes for each matched relationship
Relations
— A table containing all matched relationships
Access the table of nodes.
relinfo.Nodes
ans=4×3 table
NodeLabels NodeData NodeObject
__________ ____________ ___________________________________
0 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
1 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
2 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
3 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
Access the table of relationships.
relinfo.Relations
ans=3×5 table
StartNodeID RelationType EndNodeID RelationData RelationObject
___________ ____________ _________ ____________ _______________________________________
3 1 'knows' 3 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
2 2 'knows' 1 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
1 0 'knows' 1 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
Close the database connection.
close(neo4jconn)
Search for information about outgoing relationships in a Neo4j® database. Return the information as a directed graph and display the edges and nodes of the graph.
Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name
with a value ranging from User1
through User7
. Each relationship has the type knows
.
Create a Neo4j database connection using the URL http://localhost:7474/db/data
, user name neo4j
, and password matlab
.
url = 'http://localhost:7474/db/data'; username = 'neo4j'; password = 'matlab'; neo4jconn = neo4j(url,username,password);
Check the Message
property of the Neo4j connection object neo4jconn
. The blank Message
property indicates a successful connection.
neo4jconn.Message
ans = []
Retrieve the origin node nodeinfo
using the Neo4j database connection and the node identifier 3
.
nodeid = 3; nodeinfo = searchNodeByID(neo4jconn,nodeid);
Search for outgoing relationships using the Neo4j database connection and the origin node nodeinfo
. Return relationship information as a directed graph by using the 'DataReturnFormat'
name-value pair argument with the value 'digraph'
.
direction = 'out'; relinfo = searchRelation(neo4jconn,nodeinfo,direction, ... 'DataReturnFormat','digraph')
relinfo = digraph with properties: Edges: [2×3 table] Nodes: [3×3 table]
Display the edges of the directed graph.
relinfo.Edges
ans=2×3 table
EndNodes RelationType RelationData
______________ ____________ ____________
{'3'} {'4'} {'knows'} {1×1 struct}
{'3'} {'5'} {'knows'} {1×1 struct}
Display the nodes of the directed graph.
relinfo.Nodes
ans=3×3 table
Name NodeLabels NodeData
_____ __________ ____________
{'3'} {'Person'} {1×1 struct}
{'4'} {'Person'} {1×1 struct}
{'5'} {'Person'} {1×1 struct}
Close the database connection.
close(neo4jconn)
neo4jconn
— Neo4j database connectionNeo4jConnect
objectNeo4j database connection, specified as a Neo4jConnect
object created with the function neo4j
.
nodeinfo
— Origin node informationNeo4jNode
object | numeric scalarOrigin node information, specified as a Neo4jNode
object or numeric scalar that denotes a node
identifier.
Data Types: double
direction
— Relationship direction'in'
| 'out'
Relationship direction, specified as either 'in'
for an incoming
relationship or 'out'
for an outgoing relationship. The relationships
are associated with the specified origin node.
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
relinfo =
searchRelation(neo4jconn,nodeinfo,'in','RelationTypes',{'knows'},'Distance',2)
returns the relationship information for the incoming relationships, which have the
relationship type knows
and are two or fewer nodes away from the
origin node.'RelationTypes'
— Relationship typesRelationship types, specified as a comma-separated pair consisting of
'RelationTypes'
and a character vector, string
scalar, cell array of character vectors, or string array. To search for
relationships using only one relationship type, use a character vector
or string scalar. To search for relationships using numerous
relationship types, use a cell array of character vectors or string
array.
Example: 'RelationTypes',{'knows'}
Data Types: char
| cell
| string
'Distance'
— Node distanceNode distance, specified as a comma-separated pair consisting of
'Distance'
and a positive numeric scalar. For
example, if the node distance is three,
searchRelation
returns information for nodes
that are three or fewer nodes away from the origin node
nodeinfo
.
Example: 'Distance',3
Data Types: double
'DataReturnFormat'
— Data return format'struct'
(default) | 'digraph'
Data return format, specified as the comma-separated pair consisting
of 'DataReturnFormat'
and the value
'struct'
for a structure or
'digraph'
for a digraph
object. Specify
this argument to return relationship information as a
digraph
object.
relinfo
— Relationship informationRelationship information in the Neo4j database that matches the search criteria from the origin node
nodeinfo
, returned as a structure with these
fields.
Field | Description |
---|---|
| Node identifier of the origin node
|
| Table that contains node information for each node
in the
The row names in the table are Neo4j node identifiers of the matched database nodes. |
| Table that contains relationship information for
the nodes in the
The row names in the table are Neo4j relationship identifiers. |
Note
When you use the 'DataReturnFormat'
name-value
pair argument with the value 'digraph'
, the
searchRelation
function returns relationship
information in a digraph
object. The resulting
digraph
object contains the same data as the
digraph
object created when you execute the
neo4jStruct2Digraph
function using the relinfo
output argument.
close
| neo4j
| Neo4jRelation
| searchGraph
| searchNode
| searchNodeByID
| searchRelationByID
You have a modified version of this example. Do you want to open this example with your edits?