The easiest way would be a multi-pass where you do the filters on the
fields to create the nodes with WHERE
and then a last pass for the relationships.

Based on your code you can also do a second MERGE in the 2nd FOREACH


// create the Enrich Graph node if value is not NA
FOREACH(ignoreMe IN CASE WHEN trim(line.EnrichGraph) <> "NA" THEN [1] ELSE
[] END |
MERGE (enrichgraph:EnrichGraph { name: line.EnrichGraph }))

// create the Relationship only if both of them are not NA
FOREACH(ignoreMe IN CASE WHEN trim(line.EnrichFile) <> "NA" THEN [1] ELSE
[] END |
MERGE (enrich:EnrichedFile { name: line.EnrichFile })
FOREACH(ignoreMe IN CASE WHEN trim(line.EnrichGraph) <> "NA" THEN [1] ELSE
[] END |
MERGE (enrichgraph:EnrichGraph { name: line.EnrichGraph })
                MERGE (enrichgraph)-[:PRODUCES]->(enrich) ) )


On Thu, Aug 3, 2017 at 8:50 PM, Avik Pal <[email protected]> wrote:

> Hello,
>
> I am new to Neo4j and currently using 3.0 community edition.
>
> Requirement: I have an excel file with 10 columns and I have to read data
> from excel, create node and relationships accordingly. There are few rows
> in my excel sheet where the value is NA, and for those kind of records I
> need to skip node creation and adjust the relationship accordingly.
>
> I am able to skip the node creation but it is not creating the
> relationship. To me it seems like enrichgraph and enrich is not
> accessible outside that FOREACH clause. Belwo is the code:
> // create the Enrich Graph node if value is not NA
> FOREACH(ignoreMe IN CASE WHEN trim(line.EnrichGraph) <> "NA" THEN [1] ELSE
> [] END |
> MERGE (enrichgraph:EnrichGraph { title:'Enrich Graph', name:
> line.EnrichGraph }))
>
> // create the Enrich File node if value is not NA
> FOREACH(ignoreMe IN CASE WHEN trim(line.EnrichFile) <> "NA" THEN [1] ELSE
> [] END |
> MERGE (enrich:EnrichedFile { title:'Enriched File', name: line.EnrichFile
> }))
>
> // create the Relationship only if both of them are not NA
> FOREACH(ignoreMe IN CASE WHEN trim(line.EnrichFile) <> "NA" THEN [1] ELSE
> [] END |
> FOREACH(ignoreMe IN CASE WHEN trim(line.EnrichGraph) <> "NA" THEN [1] ELSE
> [] END |
> MERGE (enrichgraph)-[:PRODUCES]->(enrich) ) )
>
> Is there a way to set those as global variables or something? or is there
> another way of implementing this? Please help.
>
> Thanks,
> Avik
>
> --
> You received this message because you are subscribed to the Google Groups
> "Neo4j" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to