0

How can I get all the nodes with same index value in neo4j by java?

For example I have an index on name property of nodes, and two nodes which both have name="alice". I want to get both of nodes, when searching based on index, in java?

jszobody
  • 28,495
  • 6
  • 61
  • 72
fereshteh
  • 499
  • 5
  • 18

1 Answers1

1

Have you checked the documentation on indexing? http://docs.neo4j.org/chunked/stable/indexing.html

IndexManager index = graphDb.index();
Index<Node> idx= index.forNodes( "nodes" ); //this is the name of your index
IndexHits<Node> hits = idx.get( "name", "alice" );
LameCoder
  • 1,287
  • 7
  • 22
  • thanks,how should I deliver values in hits into Node[] mynode? – fereshteh Nov 11 '13 at 18:56
  • with getsingle method I receieve more than one element error. – fereshteh Nov 11 '13 at 18:57
  • IndexHits implements Iterator and Iterable, so you should be able to just loop through the hits. If you need it to be an actual array check this answer: http://stackoverflow.com/questions/6754554/reusable-method-to-transform-iterablet-to-t – LameCoder Nov 11 '13 at 19:44