2

Is there a way to search for a node with a specific property using py2neo? (I have a bunch of nodes with {"word": "some word"}, and I want to be able to search through nodes to find a node whose word attribute has a specific value)

chayrix
  • 51
  • 1
  • 5

1 Answers1

2

I suggest that you consider using an index for this kind of requirement. You can index the nodes against the properties you need to search for and then refer to this index for your search.

Otherwise, you're left with a reasonably non-performant Cypher query:

START n=node(*) 
WHERE n.word! = 'some word' 
RETURN n

I'd recommend against using this though as it will have to sift through the entire database and therefore be very resource hungry and slow as your database grows.

Nigel Small
  • 4,475
  • 1
  • 17
  • 15
  • Hi Nigel, I'm also using py2neo, and I'm using py2neo and neo4j to build graphs of influenza transmission for my research work. I have criteria in order to establish whether to draw an edge between two nodes, and after looking through the documentation, I wasn't able to find out how to get a node by a name, so that I can reference that node, and another node, in my code that declares a relationship between the two. Do you have any advice on how best to do this? – ericmjl Jun 26 '13 at 19:31
  • Pardon the many questions, but because I'm a newcomer to neo4j, I have another question - what is the purpose of an index? – ericmjl Jun 26 '13 at 19:43