0
votes

I have created following Indexes on Label Student in my Embedded graphDb

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

While using cypher MATCH query

This works : match (n:Student) return n;

This also works : match (n:Student) where n.Marks<30 return n;

But, This fails : match (n:Student) where n.Marks=30 return n;

And this too: match (n:Student) where n.Marks='30' return n;

Curious thing is this one works:

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

Works: I get the expected results, Fails : No result

Can anyone explain this behaviour, as all the properties are already Indexed(Label) and the cypher should return the desired result.

I have also checked if the properties are Indexed or not for the label using :

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

I am executing the cypher queries using this approach.

[EDIT] Node creation:

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();
1
I've tried it out and this just works. I did have to correct your cypher queries so they have parentheses around the node 'n' and removed a couple of ';' where they shouldn't have been.tstorms
How did you create your node with the Label 'Student' and the value for 'Marks' ? What Neo4j version are you using?Michael Hunger
I have edited the question, find it there.Akina91
I am using neo4j-community-2.0.0-M03.Akina91

1 Answers

1
votes

This just works, see the following code snippet. What's different in your script?

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();
}

Script output:

[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