title: Neo4j Spatial index error duplicates
body: <p>I'm having an error when inserting in Neo4j a spatial object with Spring Data: </p>
  
  <pre><code>Caused by: java.lang.RuntimeException: Error adding element 20 wkt POINT(-0.131483 51.513861) to index LocationIndex
  at org.neo4j.rest.graphdb.ExecutingRestAPI.addToIndex(ExecutingRestAPI.java:470)
  at org.neo4j.rest.graphdb.RestAPIFacade.addToIndex(RestAPIFacade.java:168)
  at org.neo4j.rest.graphdb.index.RestIndex.add(RestIndex.java:60)
  </code></pre>
  
  <p>That's basically because there was a different entry before (that doesn't exist anymore, with the same location). The uniqueness of the constraint means two different objects cannot have the same location, but if you delete the previous one, it seems to remain in the index and collides.</p>
  
  <p>Is there any way of re-indexing the spatial index in neo4j? That means, delete everything and re-index only the existing data.</p>
  
  <p>This is my class field in the Spring Data entity class:</p>
  
  <pre><code>@Indexed(indexType = IndexType.POINT, indexName = "LocationIndex")
  private String wkt;
  </code></pre>
  
  <p>Should I add something to delete from the index when the object is deleted? Or it must be done manually, how?</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>{
      "message": "GeometryNode not indexed with an RTree: 21",
      "exception": "RuntimeException",
      "fullname": "java.lang.RuntimeException",
      "stacktrace": [
          "org.neo4j.gis.spatial.rtree.RTreeIndex.findLeafContainingGeometryNode(RTreeIndex.java:794)",
          "org.neo4j.gis.spatial.rtree.RTreeIndex.remove(RTreeIndex.java:111)",
          "org.neo4j.gis.spatial.rtree.RTreeIndex.remove(RTreeIndex.java:100)",
          "org.neo4j.gis.spatial.EditableLayerImpl.update(EditableLayerImpl.java:56)",
          "org.neo4j.gis.spatial.indexprovider.LayerNodeIndex.add(LayerNodeIndex.java:143)",
          "org.neo4j.gis.spatial.indexprovider.LayerNodeIndex.add(LayerNodeIndex.java:41)",
          "org.neo4j.server.rest.web.DatabaseActions.addToNodeIndex(DatabaseActions.java:686)",
          "org.neo4j.server.rest.web.RestfulGraphDatabase.addToNodeIndex(RestfulGraphDatabase.java:1022)",
          "java.lang.reflect.Method.invoke(Method.java:606)",
          "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)",
          "java.lang.Thread.run(Thread.java:745)"
      ]
  }
  </code></pre>
  
  <p>Found that he is trying to acquire from DB the Index node to do something. The ID of the Node I'm trying to update in this case is <code>20</code>, see that he is trying to get <code>21</code>.</p>
  
  <p>That's because of this (found in neo4j <a href="https://github.com/neo4j/neo4j/blob/2.1-maint/community/server/src/main/java/org/neo4j/server/rest/web/RestfulGraphDatabase.java#L205" rel="nofollow">github</a>):</p>
  
  <pre><code>private long extractNodeId( String uri ) throws BadInputException
      {
          try
          {
              return Long.parseLong( uri.substring( uri.lastIndexOf( "/" ) + 1 ) );
          }
          catch ( NumberFormatException | NullPointerException ex )
          {
              throw new BadInputException( ex );
          }
      }
  </code></pre>
  
  <p>I don't understand how this is suppose to work, because in my Database I've seen nodes with ID different than OriginalNode + 1 which point correctly to the OriginalNode's ID and spatial finds them.</p>
  
  <p>Is it only a matter of update? If I create OriginalNode with wkt it creates both nodes all right, but this error only shows up when I'm trying to add wkt information to an existing node.</p>
  
  <p>Thanks!</p>