Search code examples
neo4jcypherneo4j-apoc

neo4j cypher create relation between two nodes based on an attribute String value


I have a Node with Label Experiment with an attribute called ExperimentName.

This ExperimentName is based on the concatenation of 3 different variables

"Condition (ExperimentProfile1) Dose"

Example :

Control diet (MOA77) LD
Control gavage(MOA66) HD

I have another Node called ExperimentMapper it has 3 attributes : - Condition - ExperimentProfile - Dose

I would like to create a Relation between Node Experiment and Node ExperimentMapper when experimentName is the results of the 3 attributes assembled.

I have tried to use Regex but the query was extremely slow and took forever..

Any help?

This is my cypher but it is taking forever despite me creating indexes

MATCH (mxpExperiment:MxpExperiment) OPTIONAL MATCH (otuExperimentMapper:OtuExperimentMapper) 
WHERE  mxpExperiment.name CONTAINS otuExperimentMapper.Condition 
AND mxpExperiment.name CONTAINS otuExperimentMapper.Experiment
AND mxpExperiment.name CONTAINS otuExperimentMapper.dose

CREATE (mxpExperiment)-[:OTU_EXPERIMENT_MAPPER]->(otuExperimentMapper)
RETURN mxpExperiment, otuExperimentMapper

Solution

  • I think that you need to go from the side of the Experiment Mapper.

    First you need to create an index:

    CREATE INDEX ON :MxpExperiment(name)
    

    Then the query can be as follows:

    MATCH (otuExperimentMapper:OtuExperimentMapper) 
    WITH otuExperimentMapper,
         otuExperimentMapper.Condition  + ' (' +
         otuExperimentMapper.Experiment + ') ' +
         otuExperimentMapper.dose AS name
    MATCH (mxpExperiment:MxpExperiment) WHERE mxpExperiment.name = name
    MERGE (mxpExperiment)-[:OTU_EXPERIMENT_MAPPER]->(otuExperimentMapper)
    RETURN mxpExperiment, otuExperimentMapper