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

查看:31
本文介绍了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}

但是,当使用密码查询时,我没有得到任何结果(我尝试颠倒 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

休息:

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"}

(作为回应,检查self"并找到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}

推荐答案

我对此进行了调查,它与我们见过几次的问题有关.空间库的设计有一个不一致的地方,就是在空间索引中添加节点的方式有两种.一种是将其添加到层(使用 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 可以评论),在这种情况下你不能使用密码调用.

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:

START n=node(13065) MATCH (n)<-[r:RTREE_REFERENCE]-() DELETE 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天全站免登陆