neo4jspring-data-neo4jneo4j-ogmspring-data-neo4j-5

Spring Data Neo4j @Index annotation on collection property


will the SDN @Index work properly on the collection properties, something like this:

@Index(unique = false)     
private Set<Long> optionIds; 

Solution

  • This is possible and should work, an index should be created on property optionIds for given label.

    But most likely this will not work as you expect. The problem comes from how Neo4j indexes arrays (and the fact it can't index sets - only lists and it can't index individual elements from arrays).

    Whole arrays will be indexed and then can be looked up by whole arrays again. If you want to do index lookups by whole sets use sorted sets so the ids are always in the same order in the stored array (Set is stored as array by OGM).

    You can't do index lookups by individual elements from the indexed array.