简体   繁体   中英

Cypher Query not finding Node

I have created an embedded Neo4J in a Java project like this:

graphDb = new GraphDatabaseFactory()
            .newEmbeddedDatabaseBuilder("db")
            .setConfig(GraphDatabaseSettings.node_keys_indexable, "movieId, userId, rating, genre")
            .setConfig(GraphDatabaseSettings.node_auto_indexing, "true")
            .newGraphDatabase();

I have verified that the index is created, and it has the name that I expect:

Index<Node> index = graphDb.index().forNodes("movieId");
System.out.println("::: Verify Index Name :::");
System.out.println(index.getName());

The console shows:

::: Verify Index Name :::
movieId

I can find the node using the Java API

ReadableIndex<Node> graphDbIndex = graphDb.index().getNodeAutoIndexer().getAutoIndex();
Node movie = graphDbIndex.get("movieId", 2).getSingle();
System.out.println("::: Get with Java API Result :::");
System.out.println("MovieId: " + movie.getProperty("movieId"));
System.out.println("Title: " + movie.getProperty("title"))

The console shows

::: Get with Java API Result :::
MovieId: 2
Title: Jumanji (1995)

But when I try with Cypher this is the result

ExecutionEngine engine = new ExecutionEngine(graphDb);
ExecutionResult result = engine.execute("start movie=node:movieId(movieId='2') return movie, movie.title");
System.out.println("::: get with Cypher Result :::");
System.out.println(result);

The console shows

::: get with Cypher Result :::
+---------------------+
| movie | movie.title |
+---------------------+
+---------------------+
0 row
8 ms

Am I doing something very wrong or have I just missed something obvious?

Thanks.

Is the id a string? Try like this with the lucene index syntax:

start movie=node:node_auto_index('movieId:2') 
return movie, movie.title

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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