我在Java项目中创建了一个嵌入式Neo4J,如下所示:
graphDb = new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder("db")
.setConfig(GraphDatabaseSettings.node_keys_indexable, "movieId, userId, rating, genre")
.setConfig(GraphDatabaseSettings.node_auto_indexing, "true")
.newGraphDatabase();
我已经验证索引已创建,并且它具有我期望的名称:
Index<Node> index = graphDb.index().forNodes("movieId");
System.out.println("::: Verify Index Name :::");
System.out.println(index.getName());
控制台显示:
::: Verify Index Name :::
movieId
我可以使用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"))
控制台显示
::: Get with Java API Result :::
MovieId: 2
Title: Jumanji (1995)
但是当我尝试使用Cypher时,这就是结果
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);
控制台显示
::: get with Cypher Result :::
+---------------------+
| movie | movie.title |
+---------------------+
+---------------------+
0 row
8 ms
我做错了什么或者我错过了一些明显的东西?
感谢。
答案 0 :(得分:3)
id是字符串吗?尝试使用lucene索引语法:
start movie=node:node_auto_index('movieId:2')
return movie, movie.title