cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Variable `a` not defined (line 20, column 32 (offset: 961))

I am new to Neo4j and experimenting with it. Please assist.

Blog I followed : Cypher: LOAD JSON from URL AS Data - Neo4j Graph Database Platform
File name : citeaa

    "citation":

[
{"id":1388,
"authors":[{"name":"Pranava K. Jha","id":2718958994}],
"title":"Further Results on Independence in Direct-Product Graphs.",
"year":2000,
"n_citation":1,
"page_start":"",
"page_end":"",
"doc_type":"Journal",
"publisher":"",
"volume":"56",
"issue":"",
"doi":"",
"fos":[{"name":"Graph","w":0.0},{"name":"Discrete mathematics","w":0.45872},{"name":"Combinatorics","w":0.4515},{"name":"Direct product","w":0.59104},{"name":"Mathematics","w":0.42784}],
"venue":{"raw":"Ars Combinatoria","id":73158690,"type":"J"}}

Below is my query and above is my JSON data. I don't know why I can't load data it just complains with all the tweak I tried.

devendra@neo4j> WITH "file:///citeaa" AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.citations as q
MERGE (citation:citations {id:q.id}) ON CREATE
SET citation.id = q.id, citation.title = q.title, citation.year = q.year, citation.n_citation = q.n_citation, citation.page_start = q.page_start, citation.page_end = q.page_end, citation.doc_type = q.doc_type, citation.publisher = q.publisher, citation.volume = q.volume, citation.issue = q.issue, citation.doi = q.doi

            MERGE (venue:venue {id:q.venue.id}) ON CREATE SET venue.id = q.venue.id, venue.raw = q.venue.raw, venue.type = q.venue.type
            MERGE (venue)-[:FOR]->(citation)

            FOREACH (a IN q.authors |
            MERGE (author:authors {name:q.authors.name, id:q.authors.id}) ON CREATE
            SET author.name = q.authors.name
            MERGE (citation)<-[:AUTHORED_BY]-(authors)
                    MERGE (citation)-[:WROTE_BY]->(authors))


            FOREACH (f IN q.fos |
               MERGE (citation)<-[:FOS_DETAILS]-(fos:Fos {name:f.name})
               MERGE (author:authors {name:a.name, id:a.id}) ON CREATE
               SET fos.name = f.name, fos.w = f.w
            );

Variable a not defined (line 20, column 32 (offset: 961))
" MERGE (author:authors {name:a.name, id:a.id}) ON CREATE"

5 REPLIES 5

ameyasoft
Graph Maven
Delete this line in the second FOREACH:
MERGE (author:authors {name:a.name, id:a.id})

Thank you I realized my mistake I copy pasted same lines on second FOREACH. However now no error but I see nothing loaded in DB. below is my modified query.

devendra@neo4j> WITH "file:///citeaa" AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.citations as q
MERGE (citation:citations {id:q.id}) ON CREATE
SET citation.id = q.id, citation.title = q.title, citation.year = q.year, citation.n_citation = q.n_citation, citation.page_start = q.page_start, citation.page_end = q.page_end, citation.doc_type = q.doc_type, citation.publisher = q.publisher, citation.volume = q.volume, citation.issue = q.issue, citation.doi = q.doi

            MERGE (venue:venue {id:q.venue.id}) ON CREATE SET venue.id = q.venue.id, venue.raw = q.venue.raw, venue.type = q.venue.type
            MERGE (venue)-[:FOR]->(citation)

            FOREACH (a IN q.authors |
            MERGE (author:authors {id:a.id}) ON CREATE
            SET author.name = a.name, author.id = a.id
            MERGE (citation)<-[:AUTHORED_BY]-(authors)
                    MERGE (citation)-[:WROTE_BY]->(authors))


            FOREACH (f IN q.fos |
               MERGE (fos:fos {name:f.name}) ON CREATE
               SET fos.name = f.name, fos.w = f.w
               MERGE (citation)<-[:FOS_DETAILS]-(fos)
            );

0 rows available after 519 ms, consumed after another 0 ms

Check your json file and after UNWIND use RETURN q limit 6 to see the data. Also I do not see any file extension and I assume you have the json file in the 'import' folder.

Oh thanks. there was a typo I used citations instead of citation. Now I do see the data. However another roadblock.

Cannot merge the following node because of null property value for 'id': (venue:venue {id: null})

How to I avoid this? I believe may be some of the venue id is null possibly. I will try googling but if you can please help me out.

Thank you again . I appreicate your help today found the last one on neo4j developer

devendra@neo4j> WITH "file:///citeaa" AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.citation as q with q where q.venue.id is not null
MERGE (citation:citations {id:q.id}) ON CREATE
SET citation.id = q.id, citation.title = q.title, citation.year = q.year, citation.n_citation = q.n_citation, citation.page_start = q.page_start, citation.page_end = q.page_end, citation.doc_type = q.doc_type, citation.publisher = q.publisher, citation.volume = q.volume, citation.issue = q.issue, citation.doi = q.doi

            MERGE (venue:venue {id:q.venue.id}) ON CREATE SET venue.id = q.venue.id, venue.raw = q.venue.raw, venue.type = q.venue.type
            MERGE (venue)-[:FOR]->(citation)

            FOREACH (a IN q.authors |
            MERGE (author:authors {id:a.id}) ON CREATE
            SET author.name = a.name, author.id = a.id
            MERGE (citation)<-[:AUTHORED_BY]-(authors)
                    MERGE (citation)-[:WROTE_BY]->(authors))


            FOREACH (f IN q.fos |
               MERGE (fos:fos {name:f.name}) ON CREATE
               SET fos.name = f.name, fos.w = f.w
               MERGE (citation)<-[:FOS_DETAILS]-(fos)
            );

This query loaded data.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online