Suggest the best way to create nodes and relationships using spark job?

Hey Everyone,

I know one way to create nodes and relationships using spark job in Scala like this

    //CREATING NODES AND RELATIONSHIPS
    df.select("easy_id","gender").distinct().write
      .mode("Overwrite")
      .format("org.neo4j.spark.DataSource")
      .option("relationship", "HAS_GENDER")
      .option("relationship.save.strategy", "keys")
      //SOURCE NODE DETAILS
      .option("relationship.source.save.mode", "Overwrite")
      .option("relationship.source.labels", ":EasyID")
      .option("relationship.source.node.properties", "easy_id:id")
      .option("relationship.source.node.keys", "easy_id:id")
      //TARGET NODE DETAILS
      .option("relationship.target.save.mode", "Overwrite")
      .option("relationship.target.labels", ":gender")
      .option("relationship.target.node.properties", "gender:Gender")
      .option("relationship.target.node.keys", "gender:Gender")
      .save()

could anyone can suggest another best way in same tech stack?
Thanks.

Hello, can you elaborate?
What are you trying to do?
Why is the above snippet not sufficient to achieve what you want to do?

I just want to create nodes and relationships in neo4j through Spark job.
this approach is okay i am able to create both but i am facing some weird behaviours in browser. sometimes I am having less nodes and sometimes more nodes. sometimes nodes display and sometimes not. why these things happening? is there any issue in my code? or save mode Overwrite is a problem? or i am doing wrong something?

@florent_biville

Have you defined node key constraints before running this?

CREATE CONSTRAINT easy_id FOR (n:EasyID) REQUIRE n.id IS NODE KEY
CREATE CONSTRAINT gender FOR (n:gender) REQUIRE n.Gender IS NODE KEY

By the way, the second label should rather be defined as Gender, not gender (and vice-versa for the property).