简体   繁体   English

尝试通过Gremlin通过REST访问Neo4j数据库进行遍历时出错

[英]Error trying to access Neo4j database through REST for traversal using Gremlin

I am using Gremlin over Neo4j Database. 我在Neo4j数据库上使用Gremlin。 I'm able to load the tinkergraph database and do gremlin traversal on it, but unable to load local-database and do the traversal on it. 我能够加载tinkergraph数据库并对其进行gremlin遍历,但无法加载本地数据库并对其进行遍历。

From tinker graph on the console i'm using following commands and it works fine: 从控制台上的修补程序图,我正在使用以下命令,它可以正常工作:

g = new TinkerGraph();
g.loadGraphXML('/db/data/graph-example-1.xml');
g.V.name    this works fine and getting the expected results.

Even from Java-code i'm able to do it. 即使使用Java代码,我也可以做到。 I send the same command as: 我发送与以下命令相同的命令:

final String scriptURI = SERVER_ROOT_URI + "ext/GremlinPlugin/graphdb/execute_script";
WebResource resource = Client.create().resource(scriptURI);
String entity = toJsonNameValuePairCollection("script", " g = new TinkerGraph();g.loadGraphXML('/db/data/graph-example-1.xml');g.V.name");
ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).entity(entity .post(ClientResponse.class);

But when I try to access data from hard-disk that I have created at 'db/data/' it's working fine in console but not through the java code. 但是,当我尝试从在“ db / data /”处创建的硬盘访问数据时,它在控制台中可以正常工作,但不能通过Java代码运行。

Console commands: 控制台命令:

g = new Neo4jGraph('db/data/'); g =新的Neo4jGraph('db / data /'); gVname gV名称

I'm getting the expected output. 我正在获得预期的输出。

But through the Java code I'm getting following error: javax.script.ScriptException: java.lang.RuntimeException: java.io.FileNotFoundException 但是通过Java代码,我得到以下错误:javax.script.ScriptException:java.lang.RuntimeException:java.io.FileNotFoundException

my java code is: 我的Java代码是:

final String scriptURI = SERVER_ROOT_URI + "ext/GremlinPlugin/graphdb/execute_script"; 最后的字符串scriptURI = SERVER_ROOT_URI +“ ext / GremlinPlugin / graphdb / execute_script”; WebResource resource = Client.create().resource(scriptURI); WebResource资源= Client.create()。resource(scriptURI); String entity = toJsonNameValuePairCollection("script", "g = new Neo4jGraph('db/data/');gVname"); 字符串实体= toJsonNameValuePairCollection(“ script”,“ g = new Neo4jGraph('db / data /'); gVname”); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).entity(entity .post(ClientResponse.class); ClientResponse响应= resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).entity(entity .post(ClientResponse.class);

in Neo4j Server, g is already bound to the server Neo4j graph instance, so you can directly use it (omit the g = new Neo4jGraph() in the REST call to the Gremlin plugin). 在Neo4j Server中,g已经绑定到服务器Neo4j图形实例,因此您可以直接使用它(在对Gremlin插件的REST调用中忽略g = new Neo4jGraph())。

Finally, if you really need to open a new database, make sure the 'db/data/' in the script is pointing where you want it. 最后,如果您确实需要打开新数据库,请确保脚本中的“ db / data /”指向您想要的位置。 It is a relative path and thus relative to the servers working dir. 它是相对路径,因此是相对于服务器工作目录的相对路径。 Maybe you can do first 也许你可以先做

dir = new File('db/data') dir.getAbsolutePath() dir =新文件('db / data')dir.getAbsolutePath()

and return that? 并退还?

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

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