Doubt with "Finding Duplicate" Cypher Query

cypher

(Sucheta) #1

Hi,

I have created a network using the following queries -


CREATE (cc:Organisation { name: "Century", dealing: "Cement", formed:1974 });
Match (cc:Organisation) WHERE cc.name = "Century"
CREATE (eway:EwayBill {name:"EwayBill", type:"Outbound", connectedTo:"SAP"}),
(sms:SMS {name:"SMS", type:"Outbound", connectedTo:"SAP"}),
(collection:Collection {name:"Collection", type:"Inbound", connectedTo:"SAP"}),
(payments:Payments {name:"Payments", type:"Outbound", connectedTo:"SAP"}),
(cc)-[:System]->(eway),(cc)-[:System]->(sms),(cc)-[:System]->(payments),(cc)-[:System ]->(collection);
MATCH (eway:EwayBill) WHERE eway.name="EwayBill"
CREATE (generate:Generate {name:"Generate", description:"Generate an Eway Bill"}),
(update:Update {name:"Update", description:"Update Vehicle Number"}),
(cancel:Cancel {name:"Cancel", description:"Cancel an  Eway Bill"}),
(eway)-[:Method]->(generate),(eway)-[:Method]->(update),(eway)-[:Method]->(cancel);

MATCH (generate: Generate) WHERE generate.name="Generate"
CREATE (pan: Pan {name:"Pan", description:"Generate a PanCard"}),
(drivingl:DrivingLicense {name:"DrivingLicense", description:"Generate a Driving License"}),
(aadhaar:Aadhar {name:"Aadhar", description:"Generate an Aadhaar Number"}),
(generate)-[:Attribute]->(pan),(generate)-[:Attribute]->(drivingl),(generate)-[:Attribute]->(aadhaar);


MATCH (update: Update) WHERE update.name="Update"
CREATE (pan: Pan {name:"Pan", description:"Generate a PanCard"}),
(drivingl:DrivingLicense {name:"DrivingLicense", description:"Generate a Driving License"}),
(aadhaar:Aadhar {name:"Aadhar", description:"Generate an Aadhaar Number"}),
(update)-[:Attribute]->(pan),(update)-[:Attribute]->(drivingl),(update)-[:Attribute]->(aadhaar);

Here is the Network -

My query like this below reference to find any duplicate -


MATCH (js:Person)-[:KNOWS]-()-[:KNOWS]-(surfer)
WHERE js.name = "Johan" AND surfer.hobby = "surfing"
RETURN DISTINCT surfer

is

MATCH (js:EwayBill)-[:Attribute]-()-[:Attribute]-(findaadhar)
WHERE js.name = "EwayBill" AND findaadhar.name = "Aadhar"
RETURN DISTINCT findaadhar

But it shows response as -

(no changes, no records)

Please help with the formation of the duplicate query.


(Paul Thomas) #2

The central EwayBill node is not linked to any other nodes via a link of type :Attribute

So the query should be ...

MATCH (js:EwayBill)--()-[:Attribute]-(findaadhar)
WHERE js.name = "EwayBill" AND findaadhar.name = "Aadhar"
RETURN DISTINCT findaadhar


(Sucheta) #3

Thanks paul.
But i am facing the issue with the Neo4j desktop version itself.
This is the output with the query

MATCH (js:EwayBill)--()-[:Attribute]-(findaadhar)
WHERE js.name = "EwayBill" AND findaadhar.name = "Aadhar"
RETURN DISTINCT findaadhar

->

I am facing this issue from a long time . I donot get proper outputs to the queries. Like -

When i type --> MATCH (n) RETURN n

My colleagues get the entire network with relationships, but i get only nodes.

Please suggest a solution.


(Paul Thomas) #4

RETURN DISTINCT findaadhar

will only return the end nodes ...
run this instead to see the full paths ...

MATCH pathx=(js:EwayBill)--()-[:Attribute]-(findaadhar)
WHERE js.name = "EwayBill" AND findaadhar.name = "Aadhar"
RETURN pathx


(Sucheta) #5

Thanks Paul.

How about this following query -->

MATCH (n) RETURN n

I want to use this query in my application. My colleagues get a proper linked to all nodes output . But i get only nodes as shown above

Please help,


(Paul Thomas) #6

MATCH (n) RETURN n

if you have 1000s of nodes in the graph, only a subset are returned based on max nodes setting in the browser. It is possible the nodes returned are not linked and therefore not shown as being linked ...

Run this ...

MATCH (n)--(m) RETURN n,m


(Sucheta) #7

Hi Paul,

I tried your query - >MATCH (n)--(m) RETURN n,m

output is -

But then i tried this query --> MATCH (n) -[r]-(m) RETURN n,r,m
Check here output with all nodes -

Is it okay i used this query --> MATCH (n) -[r]-(m) RETURN n,r,m.

Aren't the two outputs same ?


(Sucheta) #8

Thanks paul for quick assistance.

I checked this option --> Connect result nodes

Now your query --> MATCH (n)--(m) RETURN n,m is showing all the nodes.

Thanks
Sucheta


(Sucheta) #9

Paul,

I have a difficulty.
My application uploads a file , and that file uploads the data in Neo4j database. In my Neo4j Application, i already have a database present and the file uploaded also makes its entries in the same database.

So when i do --> Match (n) Return n; --> i get all the data network of both the root nodes.

So to obtain a single network , i did -
[1]
MATCH (n:Organization) RETURN n; --> ( as Organization is the root node of that uploaded file data)

output - Is only the Organisation single node.

[2]
And with this query --> MATCH (n:Organization)-[r]-(m) RETURN n,r,m

The result is just this much ->

Please help me retrieve a query that just gives one network out of the many


(Paul Thomas) #10

MATCH pathx=(n:Organization)-[*1..3]-(m) RETURN pathx

this will give you all nodes up to 3 hops from the starting node ...