Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter relationships by a property Neo4j

Tags:

neo4j

cypher

If i create some relationships with properties

CREATE (a:A)
CREATE (b:B)
CREATE (a) - [:Thing { thing:1 }] -> (b)
CREATE (a) - [:Thing { thing:2 }] -> (b)
CREATE (a) - [:Thing { thing:3 }] -> (b)
CREATE (a) - [:Thing { thing:4 }] -> (b)

Is there a way of querying them to retrieve a subset of those relationships?

If I do the following:

MATCH (a:A) - [r:Thing] -> (b:B)
where r.thing > 2
return r

I get back all 4 of the relationships not just the last two.

like image 749
Not loved Avatar asked Nov 17 '16 22:11

Not loved


People also ask

Can relationships have properties in Neo4j?

The graphs in the Neo4j Graph Data Science Library support properties for relationships. We provide multiple operations to work with the stored relationship-properties in projected graphs. Relationship properties are either added during the graph projection or when using the mutate mode of our graph algorithms.

How do I return all nodes and relationships in Neo4j?

When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. This returns the two nodes, the relationship and the path used in the query.

Which clause is used to create nodes relationships and properties in Neo4j?

Contents. The CREATE clause is used to create nodes and relationships.

How are relationships stored in Neo4j?

Properties are stored as a linked list of property records, each holding a key and value and pointing to the next property. Each node and relationship references its first property record. The Nodes also reference the first relationship in its relationship chain. Each Relationship references its start and end node.


1 Answers

Your query is correct, and the output is correct (only relationships with thing equal to 3 and 4 are returned).

I think the problem is you're only looking at the graph output instead of the row or text output (look at the view options on the left side of the results), and the auto-complete option in the corner of the graph view is on, showing the remaining relationships even if they aren't in the returned set. If you want the graph view to ONLY show what's returned in the query results, turn auto-complete off.

like image 150
InverseFalcon Avatar answered Nov 15 '22 07:11

InverseFalcon