The rapid growth in the scale and complexity of spatiotemporal trajectory data in the era of big data presents significant challenges for efficient data management and querying. Graph databases, with their inherent advantages in modeling, storing, and managing complex relationships, have emerged as a powerful tool for handling spatiotemporal trajectory data. However, as the scale of road network spatiotemporal trajectory data continues to increase, the query performance of graph databases tends to decline due to the extensive node traversal required. To address this challenge, this paper proposes a novel method for road network spatiotemporal trajectory modeling and efficient indexing within a graph database framework. The proposed method employs the Compressed Linear Reference (CLR) model to represent road network spatiotemporal trajectories. This model is specifically designed to compress and streamline the representation of trajectory data, making it more manageable within large-scale datasets. The CLR model is implemented within a graph database, where a three-layer spatiotemporal indexing structure has been designed. This structure consists of three key components: a road network spatial index, a temporal index, and a spatiotemporal path segment index. The road network spatial index is used to index the underlying road network segments, while the temporal index and the spatiotemporal path segment index handle the temporal and combined spatiotemporal aspects of trajectory data. This integrated indexing structure is designed to minimize the need for extensive node traversal during query execution, significantly improving query efficiency. In addition to the indexing structure, two spatiotemporal query methods have been developed that leverage this efficient index. These methods are tailored to meet the requirements of different application scenarios, such as identifying intersections between spatiotemporal paths and performing spatiotemporal window queries to retrieve relevant trajectory segments. To validate the effectiveness of the proposed method, extensive experiments were conducted using artificially synthesized road network spatiotemporal trajectory data based on the road network of Wuhan. The Nebula Graph database was selected as the platform for managing and storing the spatiotemporal trajectory data, and the proposed indexing and query methods were implemented within this environment. The performance of our approach was tested across datasets of varying scales to evaluate scalability and efficiency. The experimental results demonstrated that the efficient spatiotemporal index significantly outperforms the native indexing mechanisms of Nebula Graph. Specifically, the method improved the performance of spatiotemporal window-path intersection queries by a factor of at least 16.59 and enhanced spatiotemporal path-path intersection queries by a factor of at least 2.74 compared to the baseline performance. These results highlight the substantial improvements in query performance achieved by this method. © 2024 Science Press. All rights reserved.