Neo4j Spatial'WithinDistance'Cypher查询返回空,而REST调用返回数据 [英] Neo4j Spatial 'WithinDistance' Cypher query returns empty while REST call returns data

查看:71
本文介绍了Neo4j Spatial'WithinDistance'Cypher查询返回空,而REST调用返回数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有正确配置的空间层和索引,并且可以使用findGeometriesWithinDistance REST API调用成功查询节点.

I have what appears to be a correctly configured spatial layer and index and can successfully query a node using findGeometriesWithinDistance REST API call.

POST /db/data/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance {"layer":"geom","pointX":15.0,"pointY":60.0,"distanceInKm":100.0}

但是,当使用cypher进行查询时,我没有任何结果(我已经尝试过倒转60.0和15.0的顺序而没有运气):

However, when querying using cypher, I get no results (I have tried reversing the order of 60.0 and 15.0 without luck):

START n=node:geom('withinDistance:[60.0, 15.0, 500.0]') return n;

Cyper返回:

==> +---+
==> | n |
==> +---+
==> +---+
==> 0 row
==> 
==> 13 ms

REST:

200 OK
==> [ {
==>   "paged_traverse" : "http://localhost:7474/db/data/node/14472/paged/traverse/{returnType}{?pageSize,leaseTime}",
==>   "outgoing_relationships" : "http://localhost:7474/db/data/node/14472/relationships/out",
==>   "data" : {
==>     "lon" : 15.2,
==>     "bbox" : [ 15.2, 60.1, 15.2, 60.1 ],
==>     "RaceName" : "Parador Es Muy Caliente",
==>     "lat" : 60.1,
==>     "gtype" : 1
==>   },
==>   "all_typed_relationships" : "http://localhost:7474/db/data/node/14472/relationships/all/{-list|&|types}",
==>   "traverse" : "http://localhost:7474/db/data/node/14472/traverse/{returnType}",
==>   "self" : "http://localhost:7474/db/data/node/14472",
==>   "all_relationships" : "http://localhost:7474/db/data/node/14472/relationships/all",
==>   "property" : "http://localhost:7474/db/data/node/14472/properties/{key}",
==>   "properties" : "http://localhost:7474/db/data/node/14472/properties",
==>   "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/14472/relationships/out/{-list|&|types}",
==>   "incoming_relationships" : "http://localhost:7474/db/data/node/14472/relationships/in",
==>   "incoming_typed_relationships" : "http://localhost:7474/db/data/node/14472/relationships/in/{-list|&|types}",
==>   "extensions" : {
==>   },
==>   "create_relationship" : "http://localhost:7474/db/data/node/14472/relationships"
==> } ]

REST调用以重现: 创建图层:

REST Calls to reproduce: Create Layer:

POST /db/data/ext/SpatialPlugin/graphdb/addSimplePointLayer { "layer":"geom", "lat":"lat", "lon":"lon" }

创建索引:

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

创建节点:

POST /db/data/node {"lat":60.2,"lon":15.1,"RaceName":"Parador Es Muy Caliente"}

(作为回应,检查自己"并找到nodeid)

(In response, examine "self" and find nodeid)

索引节点:

POST /db/data/ext/SpatialPlugin/graphdb/addNodeToLayer {"layer":"geom", "node":"http://localhost:7474/db/data/node/###NEW_NODE_ID###"}

查找:

POST /db/data/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance {"layer":"geom","pointX":15.0,"pointY":60.0,"distanceInKm":100.0}

推荐答案

我对此进行了调查,它与我们已经看到过几次的问题有关.在空间库的设计中存在不一致之处,因为有两种方法可以将节点添加到空间索引中.一种是使用REST调用将其添加到Layer(使用addNodeToLayer REST),这将使用底层Java API,该API将节点直接连接到RTree作为同一图的一部分.另一种方法是在索引图中创建一个代理节点,以便您的域图不连接到索引图.第二种方法仅由IndexProvider接口采用(使用/db/data/index/node/geom REST调用).

I investigated this, and it is related to an issue we have seen a few times. There is an inconsistency in the design of the spatial library in that there are two ways to add a node to the spatial index. The one is to add it to the Layer (using the addNodeToLayer REST call), and this uses the underlying Java API which directly connects the node into the RTree as part of the same graph. The other is to create a proxy node in the index graph so that your domain graph is not connected to the index graph. This second approach is only taken by the IndexProvider interface (using the /db/data/index/node/geom REST call).

如果调用这两种方法,则将节点添加两次,一次直接添加,一次通过代理添加.问题在于,Cypher insideDistance索引查询仅访问IndexProvider接口,并且只会返回未同时连接到索引的节点.因此,如果您以两种方式添加该节点,将不会返回该节点.

If you call both methods, the node is added twice, once directly and once by proxy. The problem is that the Cypher withinDistance index query accesses only the IndexProvider interface, and will only return nodes that are NOT also connected to the index. So if you add the node in both ways, it will not be returned.

因此,您只需要添加以下两种方法之一即可.我在您的原始电子邮件中没有看到关于addNodeToLayer的任何提及,因此我怀疑SDN可能正在调用addNodeToLayer(也许Michael可以发表评论),在这种情况下,您不能使用cypher调用.

So you need to add it only one of the two ways. I did not see in your original email any mention of addNodeToLayer, so I suspect that SDN might be calling addNodeToLayer (perhaps Michael can comment), in which case you cannot use the cypher call.

在测试期间,我可以使用Cypher手动删除一个索引关系,如下所示:

During my testing, I was able to manually remove the one index relationship using Cypher like this:

开始n = node(13065)匹配(n)<-[r:RTREE_REFERENCE]-()删除r

START n=node(13065) MATCH (n)<-[r:RTREE_REFERENCE]-() DELETE r

将13065替换为原始节点的节点ID.

Replace the number 13065 with your node id for the original node.

我在neo4j浏览器(在2.1.2中)执行了以下操作:

I did the following in the neo4j browser (in 2.1.2):

:POST /db/data/ext/SpatialPlugin/graphdb/addSimplePointLayer { "layer":"geom", "lat":"lat", "lon":"lon" }
:POST /db/data/index/node/ {"name":"geom", "config":{"provider":"spatial", "geometry_type":"point","lat":"lat","lon":"lon"}}
:POST /db/data/node {"lat":60.2,"lon":15.1,"RaceName":"Parador Es Muy Caliente"}
:POST /db/data/index/node/geom {"value":"dummy","key":"dummy", "uri":"http://localhost:7474/db/data/node/13071"}

这创建了一个图,该图的节点未直接连接到索引.在这种情况下,REST调用"findGeometriesWithinDistance"不起作用(使用标准Java API),而密码"withinDistance"起作用.我使用以下命令进行了测试:

This created a graph with the node not directly connect to the index. In this case the REST call 'findGeometriesWithinDistance' does not work (uses standard Java API), while the cypher 'withinDistance' does work. I tested with this command:

start n = node:geom("withinDistance:[60.2,15.1,100.0]") return n

请注意,不幸的是,此API的订单顺序为lat,lon,而不是更标准的lon,lat.

Note that unfortunately this API puts the order as lat,lon, instead of the more standard lon,lat.

然后我也添加到了图层(即直接添加到索引图):

Then I also added to the layer (ie. add directly to the index graph):

:POST /db/data/ext/SpatialPlugin/graphdb/addNodeToLayer {"layer":"geom", "node":"http://localhost:7474/db/data/node/13071"}

现在,当我使用cypher命令搜索时,我仍然得到相同的正确答案,但是当我使用REST命令搜索时:

Now when I search with the cypher command I still get the same correct answer, but when I search with the REST command:

:POST /db/data/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance {"layer":"geom","pointX":15.0,"pointY":60.0,"distanceInKm":100.0}

我发现这返回了代理节点而不是原始节点.

I find this returns the proxy node instead of the original node.

这篇关于Neo4j Spatial'WithinDistance'Cypher查询返回空,而REST调用返回数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆