Say that I have an index named "user". How do I get all the nodes belonging to that index using Neo4j-Java Api?
I tried the code below
val nodeIndex = getNodeIndex("article").get
val nodes = nodeIndex.getGraphDatabase().getAllNodes()
But, I got all the nodes present in the db. How do I solve this?
You can show everything with simple MATCH (n) RETURN n , as offical documentation suggests. START n=node(*) RETURN n from Neo4j 2.0 is deprecated: The START clause should only be used when accessing legacy indexes (see Chapter 34, Legacy Indexing). In all other cases, use MATCH instead (see Section 10.1, “Match”).
When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. This returns the two nodes, the relationship and the path used in the query.
If you want to get the labels of a specify node, then use labels(node) ; If you only want to get all node labels in neo4j, then use this function instead: call db. labels; , never ever use this query: MATCH n RETURN DISTINCT LABELS(n) .
You should use "get" or "query" on the nodeIndex, like:
IndexHits<Node> allArticles = nodeIndex.query( "*:*" );
... do stuff ...
allArticles.close();
or
Node myArticle = nodeIndex.get( "name", "MyArticle" ).getSingle();
What you did above was to regardless of the index, get the graph database and return all nodes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With