The Query interface provides methods to fetch data from the graph database. This can either be done directly by providing a keys to nodes or by traversing the graph.

A Query has a state that is changed by operations performed on the query:

  • A current collection of nodes on which operations can be perfumed on.
  • A result object that is emitted once the query is run.

See Also:

Example:

  1. StartAt : Sets the current collection of nodes to all nodes of the node type
  2. Out : Follow all outgoing edges to nodes of type _FilesEntry and replace current collection of nodes with these _FilesEntry nodes.
  3. Emit : Add the current collection of nodes to the result object under the key "FilesWithMyEntity". Also fetches the field "OriginalName" of the nodes in the collection.
graph.Query(q => q.StartAt("MyEntity")
.Out("_FileEntry"))
.Emit("FilesWithMyEntity", ["OriginalName"]));


Select Nodes:

Methods to traverse the Graph:

Filter Methods:

Sort Methods:

Methods to add Data to the Result:


Available Methods on the Query Interface

StartAt

Sets the current collection of nodes to a node, a list of nodes or all nodes of a given node type.


Out

Follows outgoing edges from the current collection of nodes and replaces the current collection of nodes with the target nodes. Restricts the targets of the edges to follow to the given nodeTypes and restricts the edges to follow to only edges of the given edgeTypes. If no nodeType or edgeType are given, no restrictions are applied.

Examples:

Fetch all Authors (Person) for a given file.

This assumes the following relationship:

File - HasAuthor -> Person

  1. StartAt : Starts the query at the given file with the given id.
  2. Out : Follows all outgoing edges of type HasAuthor from this file to Person nodes.
  3. Emit : Adds this collection of authors to the emitted output under the key Authors
var myFile = "SsdKH2jhdf345S0M3UID"
teams_result = graph.Query(q => q
.StartAt(myFile)
.Out("Person", "HasAuthor")
.Emit("Authors"))

The response will include Persons and Teams related to the given file.

{

"R": {
"Authors": [
{
"U": "BW6iEUWesnKY4VrjrhVzKw",
"T": "_AccessGroup",
"C": {}
},
{
"U": "BVyHzAPixAYJqZoH9FBwM6",
"T": "_AccessGroup",
"C": {}
}
]
},
"MS": 4.0285
}


OutMany

Follows outgoing edges from the current collection of nodes and replaces the current collection of nodes with the target nodes. This is repeated for a maximum of the given number of levels. Intermediate nodes are kept and added to the current collection of nodes. Followed edges are restricted to the targets of the given nodeTypes and edges to follow to only edges of the given edgeTypes. If no nodeType or edgeType are given, no restrictions are applied. By default the results are made distinct, e.g. when a node is traversed multiple times. This can be disabled by setting distrinct to false.

Examples:

Fetch all Authors (of type Person) and the Teams they are in for a given file.

This assumes the following relationships:

File - HasAuthor -> Person

Person - InTeam -> Team

var myFile = "SsdKH2jhdf345S0M3UID";
teams_result = graph.Query(q =>
q.StartAt(myFile)
.OutMany(2, new []{"Person", "Team"}, new []{"HasAuthor" ,"InTeam"})
.Emit("Teams"));

The response will include Persons and Teams related to the given file.

{

"R": {
"Teams": [
{
"U": "BW6iEUWesnKY4VrjrhVzKw",
"T": "Person",
"C": {}
},
{
"U": "BVyHzAPixAYJqZoH9FBwM6",
"T": "Person",
"C": {}
},
{
"U": "MzmYCqZrjeddaquFAq4wwf",
"T": "Team",
"C": {}
}
]
}
}


Similar

Replaces the current collection of nodes with similar nodes based on the given similarity index.

See Also:

Models & Text pocessing


Skip

Removes the given count from the beginning of the current collection of nodes.


Take

Limits the number of nodes in the current collection of nodes by the given count. Removes all remaining nodes from the current collection of nodes.


Emit

Adds the current collection to the final output under the given emitKey. Calling Emit with a different emitKey adds another collection of nodes to the output under that new key. Adds the provided fields of the content of emitted nodes.

Examples:

  1. StartAt : Sets the current collection of nodes to the given files.
  2. Emit : Adds these files to the emitted output under the key "Files" and fetches the field "Metadata" form the current nodes ("Files").
var myFile1 = "SsdKH2jhdf345S0M3UID";
var myFile2 = "K34Ssd5H2jhdfS0M3UID";
var filesResult = graph.Query(q => q
.StartAt(new []{my_file1, my_file1})
.Emit("Files", new []{"Metadata"}))

The response will look similar to this:

{

"R": {
"Files": [
{
"U": "M1wR2dhMTkiBzAxUzJPYBS",
"T": "_FileEntry",
"C": {
"Metadata": {
"LastSavedBy": "Word 2016",
"Author": "Jon Doe"
}
}
},
{
"U": "dcBDxXDebzMP9rXBmguJvj",
"T": "_FileEntry",
"C": {
"Metadata": {
"LastSavedBy": "Word 2016",
"Author": "Jon Doe"
}
}
}
]
},
"MS": 0.1937
}


EmitCount

Adds the count of the current collection of nodes to the output under the given emitKey.

Examples:

  1. StartAt : Sets the current collection of nodes to the given files.
  2. EmitCount : Adds the count of the the current collection of nodes to the output under the given key.
var myFile1 = "SsdKH2jhdf345S0M3UID";
var myFile2 = "K34Ssd5H2jhdfS0M3UID";
var filesResult = graph.Query(q => q.StartAt([my_file1, my_file1])
.EmitCount("FilesCount"));

The response will look similar to this:

{ 
"R": {},
"C": {
"FilesCount": 2
},
"MS": 0.4819
}


EmitWithEdges

Adds the current collection to the final output under the given emitKey. Calling Emit with a different emitKey adds another collection of nodes to the output under that new key. Adds the provided fields of the content of emitted nodes. Adds all outgoing edges of the emitted node to the emitted output.

Examples:

  1. StartAt : Sets the current collection of nodes to the given files.
  2. EmitWithEdges : Adds these files to the emitted output under the key "Files" and fetches the field "Metadata" form the current nodes ("Files").
var myFile1 = Node.UID("SsdKH2jhdf345S0M3UID");
var myFile2 = Node.UID("K34Ssd5H2jhdfS0M3UID");
var filesResult = graph.Query(q => q.StartAt(my_file1, my_file1)
.EmitWithEdges("Files"))

The response will look similar to this:

{

"R": {
"Files": [
{
"U": "dcBDxXDebzMP9rXBmguJvj",
"T": "_FileEntry",
"E": [
{
"N": "_Folder",
"U": "RootFoLder111111111111",
"T": "_ParentFolder"
}
]
},
{
"U": "M1wR2dhMTkiBzAxUzJPYBS",
"T": "_FileEntry",
"E": [
{
"N": "_Folder",
"U": "RootFoLder111111111111",
"T": "_ParentFolder"
}
]
}
]
},
"MS": 0.1749
}


OfType

Filters the current collection of nodes by removing nodes that are not of the given node type.


OfTypes

Filters the current collection of nodes by removing nodes that are not of any of the given node types.


ExceptType

Filters the current collection of nodes by removing nodes that are of the given node type.


ExceptTypes

Filters the current collection of nodes by removing nodes that are of any of the given node types.


IsRelatedTo

Filters the current collection of nodes by removing nodes that do not have any outgoing edge to the given node(s) or node type(s). If nodes are given and assumeBidirectionalEdges is set to True, also removes nodes, that do have an outgoing edge, but the target node does not have an edge back. assumeBidirectionalEdges is ignored when filtered for node types.


IsNotRelatedTo

Filters the current collection of nodes by removing nodes that do have any outgoing edge to the given node node(s) or type(s). If nodes are given and assumeBidirectionalEdges is set to True, only removes nodes, that have an outgoing edge to the given node(s) and the given node(s) have an edge back.assumeBidirectionalEdges is ignored when filtered for node types.


SortByTimestamp

Sorts the current collection of nodes (and by extension the emitted results) by the timestamp. The order can be reverted, by setting the oldestFirst argument.

For files the timestamp is set to the last modified date, by default. For nodes, the timestamp is the created timestamp or a manually provided one.


SortByConnectivity

Sorts the current collection of nodes (and by extension the emitted results) by the number of outgoing edges.

Did this answer your question?