Query

Node Query

Query by Node ID

Example: Find the node whose ID is 1:

SearchNodesRequest request = new SearchNodesRequest();
request.setId(1);
List<NodeAlias> res = client.searchNodes(request);

Query by Ultipa Filter

Example: Find 10 nodes whose ID is geater than 5:

SearchNodesRequest request = new SearchNodesRequest();
request.setFilter(
 		Filter.newGtBuilder("id")
 			.gt(5)
 			.build()
);
request.setLimit(10);
List<NodeAlias> res = client.searchNodes(request);

Set Properties to Return

Example: Find nodes by ID and return properties 'name' and 'age':

SearchNodesRequest request = new SearchNodesRequest();
request.setId(nodeId);
request.setSelectProperties(Arrays.asList("name", "age"));
List<NodeAlias> res = client.searchNodes(request);

Edge Query

Query by Edge ID

Example: Find the edge whose ID is 1:

SearchEdgesRequest request = new SearchEdgesRequest();
request.setId(1);
List<EdgeAlias> res = client.searchEdges(request);

Query by Ultipa Filter

Example: Find 10 edges whose rank is 55 or 60:

SearchEdgesRequest request = new SearchEdgesRequest();
request.setFilter(
		Filter
			.newInBuilder("rank")
			.in("55", "60")
			.build()
	);
request.setLimit(10);
List<EdgeAlias> res = client.searchEdges(request);

Set Properties to Return

Example: Find edges by ID and return property 'rank':

SearchEdgesRequest request = new SearchEdgesRequest();
request.setId(edgeId);
request.setSelectProperties(Arrays.asList("rank"));
List<EdgeAlias> res = client.searchEdges(request);

A-to-B Path Query

Example: Find 5 paths between node (id = 1) and node (id = 2) whose depth is 3:

SearchABRequest request = new SearchABRequest();
request.setSrc(1);
request.setDest(2);
request.setDepth(3);
request.setLimit(5);
List<Path> paths = client.searchAB(request);

K-Hop Query

Example: Find the 2-step neighbors of node (id = 55), return 5 results and the total:

SearchKhopRequest request = new SearchKhopRequest();
request.setSrc(55);
request.setDepth(2);
request.setLimit(5);
List<NodeAlias> nodeAlias = client.searchKhop(request);

Auto-net Query

Example: Form a network using nodes ( id = [1,2,3,4]):

AutoNetRequest request = new AutoNetRequest();
request.setSrcs(Arrays.asList(1,2,3,4));
List<Path> result = client.autoNet(request);

Spread Query

Example: Spread from node (id = 12), return all the nodes and edges of 10 results within 2 steps:

NodeSpreadRequest request = new NodeSpreadRequest();
request.setSrc(12);
request.setDepth(2);
request.setLimit(10);
Result result = client.nodeSpread(request);

Template Path Query

Parameters

Configure parameters for template query using class Template.

Example: Find paths from node to edge to node using template .n().e().n():

TemplateRequest request = new TemplateRequest();
request.setTemplate(
		Template
          .newPath()
          .n()
          .e()
          .n()
          .build()
	);
Result result = client.template(request);
println(result);

Alias

Set alias for parameters and set alias to return.

Example: Find paths, return the paths and their meta-data:

TemplateRequest request = new TemplateRequest();
request.setTemplate(
		Template
          .newPath("p")
          .n("n1")
          .e("e1")
          .n("n2")
          .reTurn("p,n1,e1,n2")
          .limit(10)
          .build()
	);
Result result = client.template(request);

Filter

Example: Set node filter of 'name' equals 'June Johnson':

TemplateRequest request = new TemplateRequest();
request.setTemplate(
        Template
            .newPath("p")
            .n("n1", Filter.newEqBuilder("name").eq("June Johnson").build())
            .e("e1")
            .n("n2")
            .reTurn("p,n1.name,e1,n2")
            .limit(10)
            .build()
);
Result result = client.template(request);

Template K-Hop Query

Example: Find 1-hop neighbors of node (id = 55):

TemplateRequest request = new TemplateRequest();
request.setTemplate(
Template
	.newKhop()
	.n(Filter.newEqBuilder("id").eq("55").build())
	.e()
	.n()
	.build()
);
Result result = client.template(request);