0

We need to locate a set of objects thanks to the geolocation in a defined radius distance.

We try to use Neo4 J spacial library using SpatialRepository class to implement the method “findWithinDistance”

Bellow the used code for the implemntation with the the index type POINT to store longitude and latitude of the object :

@NodeEntity
@TypeAlias(value="MyObject")
public class MyObject{


    @GraphId Long nodeId;
    private String label;
    private String description;
    private Double lat;
    private Double lon;

    @Indexed(indexType = IndexType.POINT, indexName = "locations")
    String wkt;

    public void setLocation(float longitude, float latitude) {
          this.wkt = String.format("POINT( %.2f %.2f )",longitude,longitude);
    } 

1 ) For the first run we don’t have any problem to create the objects in neo4j database ( we can see the objects with the correct data in neo4j) For the second run or the creation of a new Object we have saying : index with the same name but different config exists!

java.lang.IllegalArgumentException: Index with the same name but different config exists!
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectRepositoryImpl': Injection of autowired dependencies failed; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Could not autowire field: org.springframework.data.neo4j.support.Neo4jTemplate fr.spart.is.neo4j.repository.ObjectRepositoryImpl.template;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'neo4jTemplate'
defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed;
nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.Neo4jTemplate org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTemplate() 
throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jMappingContext' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration:
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Index with the same name but different config exists!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)

Another point for the method that I have to implement findWithinDistance: we should make the template methods or Neo4j Cypher query to search objects?

Thank you for your help,

Do not hesitate if you need precisions

JohnMark13
  • 3,709
  • 1
  • 15
  • 26
nad
  • 1
  • Is this your only class with a spatial index? Did you always set the indexName value? Is Neo4J running embedded or against a remote server and are the spatial libraries included/installed? – JohnMark13 Oct 31 '14 at 12:11

1 Answers1

0

How do you run this?

Did you perhaps run a "pure query" variant first that caused the index to be created as lucene index and not spatial index?

You can also delete an index with the neo4j-template (you probably have to comment out the annotation for that fix to run)

Michael Hunger
  • 41,339
  • 3
  • 57
  • 80