我是neo4j
的新手,并构建 db ,其中包含> 10M 节点。在查询操作期间,我想通过使用它的两个properties
来查找节点。例如:node - name: xxx surname: yyy id:1
在查询操作期间我需要获取id
的节点name: xxx, surname: yyy
。如何使用java查询(不是密码)?并且将有多个具有给定属性的条目。
答案 0 :(得分:1)
以下是如何查找ID的示例:
GraphDatabaseService database;
Label label = DynamicLabel.label("your_label_name");
String propertyId = "id";
String propertyName = "name";
String propertySurname = "surname";
public Set<Node> getIdsForPeople(Set<Person> people) {
Set<String> ids = new HashSet<>();
try(Transaction tx = database.beginTx()) {
for (Person person in people) {
Node node = database.findNode(label, propertyName, person.getName());
if (node.hasProperty(propertySurname)) {
if (node.getProperty(propertySurname) == person.getSurname()) {
String id = node.getProperty(propertyId).toString();
ids.add(id);
}
}
}
tx.success();
}
return ids;
}
持有人
public class Person {
private final String name;
private final String surname;
public Person(String name, String surname) {
this.name = name;
this.surname = surname;
}
public String getName() { return name; }
public String getSurname() { return surname; }
}
例如
Set<Person> people = new HashSet<Person>(){{
add(new Person("xxx1", "yyy1"));
add(new Person("xxx2", "yyy2"));
add(new Person("xxx3", "yyy3");
add(new Person("xxx4", "yyy4");
}};
Set<String> ids = getIdsForPeople(people);