I have added edge doc as (name of edge is edge1)
{"_from":"test_doc2/2a","_id":"test_edge2/93615","_key":"93615","_rev":"_fcgKVwG--_","_to":"test_doc2/3a"},
{"_from":"test_doc2/3a","_id":"test_edge2/93616","_key":"93616","_rev":"_fcgKVwG--A","_to":"test_doc2/4a"}......
and vertex as(name of document is vertex1)
{"_id":"test_doc2/93490","_key":"93490","_rev":"_fcgIInG---","key":"1a","name":"abc"},
{"_id":"test_doc2/93491","_key":"93491","_rev":"_fcgIInG--_","key":"2a","name":"bcd"}......
and then making a graph in which EDGE is 'edge1' and in from and to both 'vertex1' is selected.
When I want to see this in web interface nodes are visible but not the edges. Why?
The document identifiers referenced in the _from and _to attributes of the edges do not match with the identifiers of your vertices.
For example, you reference "test_doc2/2a" but the actual value is "test_doc2/93491". The document ID is the collection name, a forward slash and the _key value (note the underscore). The values of other attributes are irrelevant, including your key attribute.
Related
I created my graph and its working as expected. My relationship table has property Name. When I merge my 2 tables (Entity 1 and Entity 2) and connect them Entity ID :
:auto USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS FROM 'file:///Rel(12March2021).csv' AS row
WITH toFloat(row.Entity1_ID) AS Entity1Id, toFloat(row.Entity2_ID) AS Entity2Id, row.Name AS Name, row.Label AS Label
MATCH (e1:Entity1 {Entity1Id: Entity1Id})
MATCH (e2:Entity2 {Entity2Id: Entity2Id})
MERGE (e2)-[rel:CONTAINS {Name: Name}]->(e1)
RETURN count(rel);
Then to display the graph, I do the following
MATCH (e2:Entity2)-[rel:CONTAINS]->(e1:Entity1)
RETURN e1, rel, e2 LIMIT 200;
As seen in the image below all relations are labelled 'Contains' with property 'Name' I want the value of the propoerty 'Name' to be displayed on the arrows instead of the word 'Contains'. Any idea how can I do that ? , For example in the highlighted arrow below I want the word 'obtain' to replace'Contains', same goes for the other relationship arrows (Note: I am using Neo4J Browser)
Same way as you do so for nodes.
Select the relationship type (in my example attached, it is CITY), then select the property to be displayed as a caption (in my example, it is since)
I'm trying to find the edge between 2 vertexes in a single query on Neptun, but something is really weird.
Here's the query
g.V().has("PRINCIPAL", "principal id", "Test User").as("principal").id().as("principal_id")
.select("principal").out().hasLabel("LICENSE").as("license").valueMap(true).as("license_vm")
.select("license").in("is attached to").as("attachments")
.select("license").inE().where(outV().hasId(select("principal").id()))
.valueMap(true)
I know it's complicated, but here's the idea:
Visit a PRINCIPAL vertex, save a reference to is as "principal" and a reference to its id as "principal_id"
Visit its out() vertices and label them as "license", I'm also saving their valuemaps for later
return to license, and get all of the in() vertices that are associated by an edge labelled "is attached to", save a reference to those as "attachments"
return to license, but now, I want to get the in-edge that points to my "principal" (from earlier). This is where it gets weird, no matter what I do here, I can't get it to recognize the principal in a where clause. THe above example fails, but if I copy-paste the literal id, it works fine
What am I missing?
Replace the where step on the second to last line of the query with:
filter(out().where(eq('principal')).by(T.id))
That should get it working.
The hasId step can take either a predicate such as gt(123) or a list of one or more ID values. That's why it works when you use the ID value.
I wanted to get two properties as results but i got only one. what i did was using the given code in gremlin
g.V().repeat(out()).until(has('title','school')).path().by('title').by('name')
how to get with both of them.
The by() modulators are applied round-robin to the Path objects so, for the first item in the path you'll get "title", then the second item will get "name", then the third item, 'title'. If you want both "title" and "name" for each vertex in the path then you need to specify that in a single by().
by() can take more than just a string (i.e. property key) as a value. It can also take a traversal and therefore you have many options to get what you want. Here's one way to do it:
g.V().repeat(out()).until(has('title','school')).
path().by(values('name','title').fold())
I have designed a model in Neo4j in order to get paths from one station to another including platforms/legs involved. The model is depicted down here. Basically, I need a query to take me from NBW to RD. also shows the platforms and legs involved. I am struggling with the query. I get no result. Appreciate if someone helps.
Here is my cypher statement:
MATCH p = (a:Station)-[r:Goto|can_board|can_alight|has_platfrom*0..]->(c:Station)
WHERE (a.name='NBW')
AND c.name='RD'
RETURN p
Model:
As mentioned in the comments, in Cypher you can't use a directed variable-length relationship that uses differing directions for some of the relationships.
However, APOC Procedures just added the ability to expand based on sequences of relationships. You can give this a try:
MATCH (start:station), (end:station)
WHERE start.name='NBW' AND end.name='THT'
CALL apoc.path.expandConfig(start, {terminatorNodes:[end], limit:1,
relationshipFilter:'has_platform>, can_board>, goto>, can_alight>, <has_platform'}) YIELD path
RETURN path
I added a limit so that only the first (and shortest) path to your end station will be returned. Removing the limit isn't advisable, since this will continue to repeat the relationships in the expansion, going from station to station, until it finds all possible ways to get to your end station, which could hang your query.
EDIT
Regarding the new model changes, the reason the above will not work is because relationship sequences can't contain a variable-length sequence within them. You have 2 goto> relationships to traverse, but only one is specified in the sequence.
Here's an alternative that doesn't use sequences, just a whitelisting of allowed relationships. The spanningTree() procedure uses NODE_GLOBAL uniqueness so there will only be a single unique path to each node found (paths will not backtrack or revisit previously-visited nodes).
MATCH (start:station), (end:station)
WHERE start.name='NBW' AND end.name='RD'
CALL apoc.path.spanningTree(start, {terminatorNodes:[end], limit:1,
relationshipFilter:'has_platform>|can_board>|goto>|can_alight>|<has_platform'}) YIELD path
RETURN path
Your query is directed --> and not all of the relationships between your two stations run in the same direction. If you remove the relationship direction you will get a result.
Then once you have a result I think something like this could get you pointed in the right direction on extracting the particular details from the resulting path once you get that working.
Essentially I am assuming that everything you are interested in is in your path that is returned you just need to filter out the different pieces that are returned.
As #InverseFalcon points out this query should be limited in a larger graph or it could easily run away.
MATCH p = (a:Station)-[r:Goto|can_board|can_alight|has_platfrom*0..]-(c:Station)
WHERE (a.name='NBW')
AND c.name='THT'
RETURN filter( n in nodes(p) WHERE 'Platform' in labels(n)) AS Platforms
i have a following graph in neo4j graph database and by using the cypher query language, i want to retrieve the whole data with is connected to root node and their child node.
For example :
kindly find the below graph image.
[As per the image, node 1 has two child and their child also have too many child with the same relationship. now what i want, using Cypher, i hit the node 1 and it should response with the whole data of child node and there child node and so on, relationship between nodes are "Parent_of" relationship.]
can anyone help me on this.
start n=node(1) // use the id, or find it using an index
match n-[:parent_of*0..]->m
return m
will get you all the graph nodes in m. You could also take m.some_property instead of m if you don't want the node itself, but some property that is stored in your nodes.
Careful though, as the path has no limit, this query could become pretty huge in a large graph.
You can see an example of *0.. here: http://gist.neo4j.org/?6608600