0
votes

I have a neo4j instance in which I have multiple types of nodes (Labels), each with their own set of properties. So, say I have:

Label "Person" with Properties ("Name","Address","Father's Name")
Label "Location" with properties ("Name","Country","City")
Label "Event" with properties ("Name","City","Country")
and so on...

Now one way is to search for a query like "xyz" when I know the specifics:

Say: match (n:Person) where n.Name="xyz" return n

My question is, is there a single 'efficient' cypher query which can do a blind search. Basically it should be able to search all Labels and all properties and give me the nodes that match. So a single query to match 'xyz' with all properties of Person, Location, Event and other Labels in my database.

I understand one way could be using an extremely long where clause, wherein I hard-code all my labels and their respective properties, but I am not looking for that. Is there a straightforward neo4j Cypher to do this?

2

2 Answers

2
votes

You can do a full graph scan which of course is O(n) type thing:

match (n) 
with n, [x in keys(n) WHERE n[x]='xyz'] as doesMatch
where size(doesMatch) > 0
return n

Another - more performant but also way more complex - approach would be implementing a TransactionEventHandler putting all properties into an legacy index and then to query on that one.

1
votes

Keep in mind that while neo4j is good for searching things when relationships are involved, or when you can constrain the nodes searched by certain labels and properties, your kind of search is not neo4j's forte. Few databases are good for this kind of all-encompassing search.

You may want to consider adding an ElasticSearch layer on top of neo4j, as it's THE tool for any kind of rich searching in a database.