0

我在这样的 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

我做错了什么还是我错过了一些明显的事情?

谢谢。

4

1 回答 1

3

id 是字符串吗?尝试使用 lucene 索引语法:

start movie=node:node_auto_index('movieId:2') 
return movie, movie.title
于 2013-03-08T00:52:17.007 回答