neo4j-spatial: What is the official way to delete a node from a spatial index?

一曲冷凌霜 提交于 2019-12-02 06:36:02

问题


My question is most certainly a duplicate of Neo4j Spatial - How To Delete A Node, but it has not yet been solved.

To my understanding removing a node from a spatial index is currently not implemented (not documented) within the neo4j-spatial-plugin.

Now my questions would be: "How do I do this myself?" I can see all the nodes of the index, but how do I query that very node that refers to the node I want to delete? And furthermore: May I just delete that node from the index without harming anything else?

Thanks :-)


回答1:


Yes. You are correct. As this link says,this is a known issue and its still open since very long.

Now, coming to your question, you can do it manually by following the below steps.

Get the internal "id" property of the indexed node, which you want to delete.

  1. Whenever any node is added to index (let's say 'geom'), then a UNIQUE RTREE_REFERENCE is added with that node. NEO4J assigns a unique id to that reference. This assigned "id" is different than the "id" which was used to index the node.e.g. Let's consider that "User" node with id:7577 is added to index "geom", using localhost:7474/db/data/node/7577.

  2. Now, after this index is created, you can check it's RTREE_REFERENCE, with the following command in Neo4j Browser.MATCH (a)-[:RTREE_REFERENCE]->(b) where b.id=7577 return b;

  3. We need to get the "internal" id of the node "b", we can do this by firing below command in the Neo4j Browser. MATCH (a)-[:RTREE_REFERENCE]->(b) where b.id=7577 return id(b);

Delete the Node from index using "internal" ID

  1. Let's say from above step, we get 7578 as the "internal/actual" id.
  2. Now, we can fire a curl command manually on the server as below curl -X DELETE http://localhost:7474/db/data/index/node/geom/7578

Cross-Verify in Database

  1. Now, if you re-query from Neo4j browser,using the below same query MATCH (a)-[:RTREE_REFERENCE]->(b) where b.id=7577 return id(b); you will get "no rows". as the RTREE_REFERENCE has been deleted.

Note : All of the above steps can be automated from your code too, using any HttpClient from Java/.Net/PHP.

Hope this answers both of your questions

Thanks



来源:https://stackoverflow.com/questions/33409461/neo4j-spatial-what-is-the-official-way-to-delete-a-node-from-a-spatial-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!