Reputation: 1788
i am using Neo4j 2.0 . I 've created many nodes with Label X and an unique property Y. I mean, this property Y is different for different nodes with Label X.
I'm using Embedded-neo4j. How can we get a node using Java API given the label X and property Y. How can U get a reference to the node?
Please help me.
Upvotes: 1
Views: 1847
Reputation: 179
In Neo4j 2.1.6 using Embedded, it can be done as :
Iterable<Node> lNodes =database.findNodesByLabelAndProperty(DynamicLabel.label("LabelInString"), "Name of Propery", lPropertyValue);
where database is instance of GraphDatabaseService.
Upvotes: 1
Reputation: 2583
Do you mean unique property Y or unique property value of attrib Y in a node. In case you have unique properties Y in nodes label X you can do below
GraphDatabaseService graphService =new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
ExecutionEngine engine = new ExecutionEngine(graphService);
String label = "X";
String property ="Y";
String query = "MATCH (n:"+label+") WHERE has(n."+property+") return n";
ExecutionResult result = engine.execute(query);
ResourceIterator<Node> resultIterator = result.columnAs("n");
Node resultNode = null;
if(resultIterator.hasNext()){
resultNode = resultIterator.next();
}
Upvotes: 0
Reputation: 19373
You can execute a Cypher query using the Java API:
match (n:X {Y:"propertyValue"}) return n
where X is the label name and Y is the property name
Upvotes: 2