我有一个包含lat和long信息的城市数据库,我正在努力让空间查询正常工作。这是我试过的:
1.创建图层
public void CreateALayer()
{
var restClient = new RestClient(new Uri(baseUri + "/db/data/ext/SpatialPlugin/graphdb/addSimplePointLayer"));
var request = new RestRequest(Method.POST);
request.AddJsonBody(
new
{
layer = "geom",
lat = "lat",
lon = "lon"
});
var response = restClient.Execute(request);
Console.WriteLine(response.Content);
}
2。将ID分配给neo4j的ID 使用以下Cypher Query将城市节点的id属性设置为Neo4j:
MATCH (n:City) SET n.id = id(n)
第3。将节点添加到索引和图层
var nodeIds = client.Cypher.Match("(n:City)").Return(n => n.As<City>().id).Results.ToList(); ;
foreach (var id in nodeIds)
{
AddNodeToIndex(id);
AddNodeToLayer(id);
}
//
public void AddNodeToIndex( long nodeId)
{
string URINode = string.Format("{0}/db/data/node/{1}", baseUri, nodeId);
//# Create geom index
var restClient = new RestClient(new Uri(baseUri + "/db/data/index/node/" + indexName));
var request = new RestRequest(Method.POST);
request.AddJsonBody(
new
{
value = "dummy",
key = "dummy",
uri = URINode
});
var response = restClient.Execute(request);
Console.WriteLine(response.Content);
}
//
public void AddNodeToLayer(long nodeId)
{
string URINode = string.Format("{0}/db/data/node/{1}", baseUri, nodeId);
string URIAdd = string.Format("{0}/db/data/ext/SpatialPlugin/graphdb/addNodeToLayer", baseUri);
/*string json = string.Format("{{\"layer\":\"{0}\", \"node\":\"{1}\"}}", layer, URINode);
HTTPCommand(new Uri(URIAdd), json);*/
var restClient = new RestClient(new Uri(URIAdd));
var request = new RestRequest(Method.POST);
request.AddJsonBody(
new
{
layer = indexName,
node = URINode
});
var response = restClient.Execute(request);
Console.WriteLine(response.Content);
}
我正在尝试运行以下查询,它不断返回我没有行。
START n=node:geom('withinDistance:[27.97,77.58, 10000000]') RETURN n
有人可以指出我在这里可能缺少的东西。
编辑1: 当我发布以下消息时,我看到了
:POST /db/data/index/node {"name":"geom", "config":{"provider":"spatial", "geometry_type":"point","lat":"lat","lon":"lon"}}
我在日志中收到此错误:
2015-12-18 04:44:38.094+0000 ERROR [o.n.k.KernelHealth]: setting TM not OK. Kernel has encountered some problem, please perform necessary action (tx recovery/restart)
java.lang.AbstractMethodError: org.neo4j.gis.spatial.indexprovider.SpatialIndexImplementation.newApplier(Z)Lorg/neo4j/kernel/impl/transaction/command/NeoCommandHandler;
at org.neo4j.kernel.impl.api.LegacyIndexApplierLookup$Direct.newApplier(LegacyIndexApplierLookup.java:48) ~[neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.api.LegacyIndexApplier.applier(LegacyIndexApplier.java:91) ~[neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.api.LegacyIndexApplier.visitIndexCreateCommand(LegacyIndexApplier.java:163) ~[neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.api.CommandApplierFacade.visitIndexCreateCommand(CommandApplierFacade.java:274) ~[neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.index.IndexCommand$CreateCommand.handle(IndexCommand.java:314) ~[neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.api.CommandApplierFacade.visit(CommandApplierFacade.java:82) ~[neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.api.CommandApplierFacade.visit(CommandApplierFacade.java:45) ~[neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation.accept(PhysicalTransactionRepresentation.java:69) ~[neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.api.TransactionRepresentationStoreApplier.apply(TransactionRepresentationStoreApplier.java:108) ~[neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess.applyToStore(TransactionRepresentationCommitProcess.java:107) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess.commit(TransactionRepresentationCommitProcess.java:64) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.api.KernelTransactionImplementation.commit(KernelTransactionImplementation.java:502) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.api.KernelTransactionImplementation.close(KernelTransactionImplementation.java:418) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.index.LegacyIndexStore.getOrCreateIndexConfig(LegacyIndexStore.java:201) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.index.LegacyIndexStore.getOrCreateNodeIndexConfig(LegacyIndexStore.java:63) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.api.StateHandlingStatementOperations.nodeLegacyIndexCreateLazily(StateHandlingStatementOperations.java:1318) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.api.OperationsFacade.nodeLegacyIndexCreateLazily(OperationsFacade.java:820) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.coreapi.IndexProviderImpl.getOrCreateNodeIndex(IndexProviderImpl.java:51) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.kernel.impl.coreapi.IndexManagerImpl.forNodes(IndexManagerImpl.java:81) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.server.rest.web.DatabaseActions.createNodeIndex(DatabaseActions.java:391) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.server.rest.web.RestfulGraphDatabase.jsonCreateNodeIndex(RestfulGraphDatabase.java:834) [neo4j-desktop-2.2.3.jar:2.2.3]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_72]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_72]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_72]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_72]
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) [neo4j-desktop-2.2.3.jar:2.2.3]
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205) [neo4j-desktop-2.2.3.jar:2.2.3]
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139) [neo4j-desktop-2.2.3.jar:2.2.3]
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302) [neo4j-desktop-2.2.3.jar:2.2.3]
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) [neo4j-desktop-2.2.3.jar:2.2.3]
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) [neo4j-desktop-2.2.3.jar:2.2.3]
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) [neo4j-desktop-2.2.3.jar:2.2.3]
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) [neo4j-desktop-2.2.3.jar:2.2.3]
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542) [neo4j-desktop-2.2.3.jar:2.2.3]
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473) [neo4j-desktop-2.2.3.jar:2.2.3]
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419) [neo4j-desktop-2.2.3.jar:2.2.3]
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409) [neo4j-desktop-2.2.3.jar:2.2.3]
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409) [neo4j-desktop-2.2.3.jar:2.2.3]
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558) [neo4j-desktop-2.2.3.jar:2.2.3]
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733) [neo4j-desktop-2.2.3.jar:2.2.3]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:800) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.server.Server.handle(Server.java:497) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:620) [neo4j-desktop-2.2.3.jar:2.2.3]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:540) [neo4j-desktop-2.2.3.jar:2.2.3]
at java.lang.Thread.run(Unknown Source) [na:1.7.0_72]
由于我不是Java专家,我不想知道我是否错过了任何包。
答案 0 :(得分:0)
您无需将该节点添加到图层和索引中。有关详细说明,请参阅https://stackoverflow.com/a/25446475/2954199,但看起来如果将节点添加到图层和索引中,则Cypher调用使用的IndexProvider将不会正确返回节点。
因此,请尝试仅将节点添加到索引(使用/db/data/index/node/geom
REST调用)而不是/addNodeToLayer
,它应该可以正常工作。