Cypher query tuning

Default Cypher® parameters are optimized for the general use case. However, the Spark connector supports all the query tuning options described in the Cypher manual.

All the examples in this page assume that the SparkSession has been initialized with the appropriate authentication options. See the Quickstart examples for more details.

Specify the Cypher version

You can change the Cypher version using the cypher.version option.

Example
val df = spark.read
    .format("org.neo4j.spark.DataSource")
    .option("query", "MATCH (o: Object) RETURN o")
    .option("cypher.version", "25")
    .load()
Example
df = (
    spark.read.format("org.neo4j.spark.DataSource")
    .option("query", "MATCH (o: Object) RETURN o")
    .option("cypher.version", "25")
    .load()
)
Equivalent Cypher query
CYPHER 25
MATCH (o: Object) RETURN o

Add query tuning parameters

You can add any tuning option described in the Cypher manual using the cypher.tuning prefix in a Spark option. All the tuning options are added to the Cypher query as CYPHER preambles.

Example
val df = spark.read
    .format("org.neo4j.spark.DataSource")
    .option("query", "MATCH (o: Object) RETURN o")
    .option("cypher.tuning.runtime", "parallel")
    .load()
Example
df = (
    spark.read.format("org.neo4j.spark.DataSource")
    .option("query", "MATCH (o: Object) RETURN o")
    .option("cypher.tuning.runtime", "parallel")
    .load()
)
Equivalent Cypher query
CYPHER runtime=parallel
MATCH (o: Object) RETURN o

You are also free to add multiple parameters this way, simply add them separately like so.

Example
val df = spark.read
    .format("org.neo4j.spark.DataSource")
    .option("query", "MATCH (o: Object) RETURN o")
    .option("cypher.tuning.runtime", "parallel")
    .option("cypher.tuning.operatorEngine", "interpreted")
    .load()
Example
df = (
    spark.read.format("org.neo4j.spark.DataSource")
    .option("query", "MATCH (o: Object) RETURN o")
    .option("cypher.tuning.runtime", "parallel")
    .option("cypher.tuning.operatorEngine", "interpreted")
    .load()
)
Equivalent Cypher query
CYPHER runtime=parallel operatorEngine=interpreted
MATCH (o: Object) RETURN o

Tuning feature compatibility

In the above examples we illustrated using custom read query for the sake of simplicity. While the examples above show how to tune preambles and change the Cypher version for read queries, the same features can be used for writing as well as other operations.

Table 1. Supported States
When using cypher.version cypher.tuning

.option("labels")

Reads & writes

Reads & writes

.option("relationship")

Reads & writes

Reads & writes

.option("query")

Reads & writes

Reads & writes

.option("gds")

Only for reads

No tuning allowed