I imported data to an empty neo4j database from CSV. I checked the schema of the imported data using the following command.
CALL db.schema.visualization()
The schema shows an unexpected edge between two types of nodes. I used the following query to find all the edges between two types of nodes.
match (s:Person)-[e]->(t:Paper) return s, t;
As expected, this query returns no results. Hence, the graph does not contain an edge between Person
and Paper
as expected, though I am not sure why the schema shows an edge between these two types of nodes.
Am I correct in assuming the schema visualized using the above query may have added edges between nodes that may not have an instance in the graph? And if so, is there any way to avoid it?
There have been other community posts experiencing the same thing. I investigated one where the visualization showed a relationships, but when queried for the relationship none were found.
Thanks for clarifying that. Is there any better way of getting schema visualization?
I suppose the following is your suggested query.
CALL apoc.meta.stats();
This is useful, though it gives more stats than schema, which is less intuitive than CALL db.schema.visualization()
. I also tried the following, which provides detailed information about the schema but is also less intuitive.
CALL apoc.meta.schema() YIELD value as schemaMap
True, but you don't need to consume everything. Here is an example where I just return the relationships and their counts.
CALL apoc.meta.stats() yield relTypes
UNWIND keys(relTypes) as relationship
return relationship, relTypes[relationship] as count
Here is the relationships and their count:
CALL apoc.meta.stats() yield relTypesCount
UNWIND keys(relTypesCount) as relationship
return relationship, relTypesCount[relationship] as count

I am seeing the same behavior, in the Community Edition 4.4.12. I can reproduce it. To explain it as simply as possible:
I create several nodes like (A)-[relation1]-(B). The schema looks correct.
I create several nodes like (B)-[relation2]-(C). The schema shows these correctly.
The schema also shows edges like (C)-[relation1]-(B). This is incorrect, B and C only have relation2.
It's not like the schema program is making up a random name, it is reusing relation1.
Can we report bugs in Community Edition?
Can someone verify whether this happens in Enterprise Edition?