0
votes

I have a database of cities with lat and long information and I am trying to get the spatial query working. Here is what I tried:

1.Create a Layer

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. Assign id to neo4j's Id Set the id property of the city nodes to Neo4j using the following Cypher Query :

MATCH (n:City) SET n.id = id(n)

3. Added the nodes to the index and layer

    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);
    }

I can see that the nods are getting created , but not sure if that is correct though: enter image description here

I am trying to run the following query and it keeps returning me no rows. START n=node:geom('withinDistance:[27.97,77.58, 10000000]') RETURN n

enter image description here

Can some one please point me what I may be missing here.

EDIT 1: I see that when I post the following message

:POST /db/data/index/node {"name":"geom", "config":{"provider":"spatial", "geometry_type":"point","lat":"lat","lon":"lon"}}

I get this error in the logs:

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]

As I am not a Java expert, I am not curious to know if I missed any package here.

1

1 Answers

0
votes

You don't need to add the node to both the layer and the index. See https://stackoverflow.com/a/25446475/2954199 for a detailed explanation, but it appears that if you add the node to both the layer and the index then the IndexProvider used by the Cypher call will not return the nodes correctly.

So try only adding the nodes to the index (using the /db/data/index/node/geom REST call) and not /addNodeToLayer and it should work.