cancel
Showing results for 
Search instead for 
Did you mean: 

My GraphQL queries are timing out - will the Neo4j GraphQL library support indexing for numbers?

Hi,

I'm using the Neo4j GraphQL library to build an app, but I'm running into a problem with queries that time out, even though my database only contains a small amount of data (about 200 objects). So now I'm trying to add indexes to my schema to make the query faster.

In the query that times out, I'm looking for events that fall between certain time slots:

 

query {
	events (where: {
    AND: [
      {
        // other filters omitted
      },
      {
        OR: [
          {
            AND: [
              {
                startTimeHourOfDay_LTE: 21
              },
              {
                startTimeHourOfDay_GTE: 18
              },
              {
                startTimeDayOfWeek: "0"
              }
            ]
          },
          {
            AND: [
              {
                startTimeHourOfDay_LTE: 21
              },
              {
                startTimeHourOfDay_GTE: 18
              },
              {
                startTimeDayOfWeek: "1"
              }
            ]
          },
          {
            AND: [
              {
                startTimeHourOfDay_LTE: 21
              },
              {
                startTimeHourOfDay_GTE: 18
              },
              {
                startTimeDayOfWeek: "2"
              }
  // More time slots here - Could be dozens of time slots

If it completes, this query often takes at least 30 seconds .

Based on this blog post (https://neo4j.com/blog/neo4j-2-2-query-tuning/) , I figured that to speed this up, I would have to assert an index on `startTimeHourOfDay`, and then look up values in a range. But according to the Neo4j GraphQL library docs (https://neo4j.com/docs/graphql-manual/current/type-definitions/indexes-and-constraints/#type-definit... it is only documented to add and index to a text field, not to a number field. Can I add an index for the startTimeHourOfDay with an annotation on my schema?

And if I can do that, do I also need to update my query to use startTimeHourOfDay_IN: [Int], since it looks like no range check is available?

Just trying to figure out if what I'm trying to do is possible with this library.

1 REPLY 1

My event schema is like this:

 

    type Event {
    id:                    ID! @id
    startTime:             DateTime!
    startTimeYear:         String!
    startTimeMonth:        String!
    startTimeDayOfMonth:   String!
    startTimeDayOfWeek:    String!
    startTimeHourOfDay:    Int!
    endTime:               DateTime!
   ...more fields
  }