Hello Neo4j Community,
I would like clarification on how Neo4j handles indexing for array properties. Specifically, does Neo4j index the individual elements within an array, or does it treat the entire array as a single value when creating an index? Additionally, I want to confirm if the index is utilized when querying for specific elements within the array.
Examples:
Consider the following scenario:
-
I create a
Person
node with an array propertyfriendshipYears
:CREATE (p:Person {name: "Alice", friendshipYears: [2018, 2019, 2020]});
-
I then create an index on the
friendshipYears
property:CREATE INDEX FOR (p:Person) ON (p.friendshipYears);
-
I run the following query to find
Person
nodes where2020
is one of thefriendshipYears
:MATCH (p:Person) WHERE 2020 IN p.friendshipYears RETURN p;
My questions are:
-
Does Neo4j index each element in the
friendshipYears
array (e.g.,2018
,2019
, and2020
as separate entries), or is the entire array[2018, 2019, 2020]
indexed as a single value? -
When querying with
WHERE 2020 IN p.friendshipYears
, does Neo4j use the index, or does it perform a full scan of thePerson
nodes? -
How can I confirm that the index is being utilized in this case? Would running
PROFILE
on the query show anIndex Seek
?
Understanding this behavior is crucial for optimizing queries and deciding on the appropriate data model for cases involving arrays.
Thank you in advance for your help!