cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Best way to index a datetime field

hi,
i'm working on an app with the neo4jGraphQL, in its scenario we need to work a lot with datetimes, so we want to index on the fields with the datetime type which are not really unique so we coudnt use @unique ,but what is the best way of indexing a datetime field.
note : i thought that one way is to cast datetimes to integer and use @unique directive, but the problem is that our fields are not really unique and may have repeated datetimes.
is it a good idea to cast datetime to string and use @fulltextindex directive?
is there another better solution?
tnx before your helps...

1 ACCEPTED SOLUTION

The best way to do this is just create a regular index on a property that has datetime stamps.

 

Here's a link to the docs that describes this scenario: https://neo4j.com/docs/cypher-manual/current/syntax/temporal/#cypher-temporal-index

 

It supports ranged queries and equality, so this is a good fit when the use case is looking up a particular instant in time, or a range of values (i.e. from midnight yesterday to midnight today to capture an entire day's range)

In general, I'd definitely recommend using neo4j temporal types on the properties, and not using strings.  Using strings will work, but it will force all of the timezone, time math, date math, and all of that type of code up into the next layer of your app rather than letting the database do it for you.

View solution in original post

1 REPLY 1

The best way to do this is just create a regular index on a property that has datetime stamps.

 

Here's a link to the docs that describes this scenario: https://neo4j.com/docs/cypher-manual/current/syntax/temporal/#cypher-temporal-index

 

It supports ranged queries and equality, so this is a good fit when the use case is looking up a particular instant in time, or a range of values (i.e. from midnight yesterday to midnight today to capture an entire day's range)

In general, I'd definitely recommend using neo4j temporal types on the properties, and not using strings.  Using strings will work, but it will force all of the timezone, time math, date math, and all of that type of code up into the next layer of your app rather than letting the database do it for you.