繁体   English   中英

Neo4j密码匹配查询不起作用

[英]Neo4j cypher MATCH query not working

我在嵌入式graphDb Label Student上创建了以下索引

Schema schema = graphDb.schema();    
indexDefinition = schema.indexFor(DynamicLabel.label("Student")).on("NodeType").create();
indexDefinition = schema.indexFor(DynamicLabel.label("Student")).on("Marks").create();

在使用密码MATCH查询时

这样工作: match (n:Student) return n;

这也适用: match (n:Student) where n.Marks<30 return n;

但是,这失败了: match (n:Student) where n.Marks=30 return n;

这也是: match (n:Student) where n.Marks='30' return n;

奇怪的是,这一项有效:

start n=node(127) match (n:Student) where n.Marks=30 return n;

作品:我得到了预期的结果,失败:没有结果

任何人都可以解释这种行为,因为所有属性都已经被索引(标签),并且密码应该返回期望的结果。

我还使用以下命令检查了标签的属性是否已编入索引:

Label label1 = DynamicLabel.label("Student");
System.out.println(schema.getIndexes(label1));

我正在使用这种方法执行密码查询。

[编辑]节点创建:

Integer marks = 30;
Label label = DynamicLabel.label("Student");
tx = graphDb.beginTx();
Node studentNode = graphDb.createNode(label);
studentNode.setProperty("NodeType", "Student");
studentNode.setProperty("Marks", marks);
tx.success();

这样就可以了,请参阅以下代码段。 您的脚本有什么不同?

final GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase();
final ExecutionEngine cypher = new ExecutionEngine(graphDb);
try (Transaction tx = graphDb.beginTx()) {
    Schema schema = graphDb.schema();
    //schema.indexFor(DynamicLabel.label("Student")).on("NodeType").create();
    schema.indexFor(DynamicLabel.label("Student")).on("marks").create();
    Label label1 = DynamicLabel.label("Student");
    System.out.println(schema.getIndexes(label1));
    tx.success();
}
try (Transaction tx = graphDb.beginTx()) {
    Node node = graphDb.createNode(DynamicLabel.label("Student"));
    node.setProperty("marks", 20);
    node = graphDb.createNode(DynamicLabel.label("Student"));
    node.setProperty("marks", 30);
    node = graphDb.createNode(DynamicLabel.label("Student"));
    node.setProperty("marks", 40);
    System.out.println(cypher.execute("match (n:Student) return n").dumpToString());
            System.out.println(cypher.execute("match (n:Student) where n.marks<30 return n;").dumpToString());
    System.out.println(cypher.execute("match (n:Student) where n.marks=30 return n;").dumpToString());
    System.out.println(cypher.execute("match (n:Student) where n.marks='30' return n;").dumpToString());
    tx.success();
}

脚本输出:

[IndexDefinition[label:Student, on:marks]]
+-------------------+
| n                 |
+-------------------+
| Node[0]{marks:20} |
| Node[1]{marks:30} |
| Node[2]{marks:40} |
+-------------------+
3 rows

+-------------------+
| n                 |
+-------------------+
| Node[0]{marks:20} |
+-------------------+
1 row

+-------------------+
| n                 |
+-------------------+
| Node[1]{marks:30} |
+-------------------+
1 row

+---+
| n |
+---+
+---+
0 row

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM