简体   繁体   中英

Neo4j query debugging on

I am trying to modify an existing neo4j cypher query in scala code which work but when I try to run the query below in debugger it gives me the error as below: Query:

START  doc = node:entities(type = "document-link")
MATCH  category-[:category]-doc<-[:`document-link`]-project-[?:`iati-identifier`]-id
RETURN COALESCE(project.`iati-identifier`?, id.`iati-identifier`?) as id,
   doc.title!                                                  as title,
   COALESCE(doc.format?, "text/plain")                         as format,
   doc.url                                                     as url,
   COLLECT(COALESCE(category.category?, ""))                   as categories

The error I get Question mark is no longer used for optional patterns - use OPTIONAL MATCH instead (line 2, column 64) " MATCH category-[:category]-doc<-[: document-link ]-project-[?: iati-identifier ]-id"

How can I rewrite the query so that it can be ran in the debugger as that will then allow me write my modification test the new cypher. Additionally, why is the debugger not willing to accept the code that I know is working in the main code base?

sorry wanted to attach an image but I don't have enough reputation yet to post images.

Not sure what you mean about the debugger, but the ? for an optional pattern hasn't been supported for a while now. Which version of Neo4j are you using? The error message indicates that the version you're using does not support the ? so you will have to rewrite your query using OPTIONAL MATCH.

It looks like your :iati-identifier relation is optional so move that into the OPTIONAL MATCH and then if it exists it will be matched, else id will be null. Similarly remove all the ? from the properties in the return statement- they'll just be null if missing.

START  doc = node:entities(type = "document-link")
MATCH  category-[:category]-doc<-[:`document-link`]-project
OPTIONAL MATCH project-[:`iati-identifier`]-id
RETURN COALESCE(project.`iati-identifier`, id.`iati-identifier`) as id,
   doc.title                                                  as title,
   COALESCE(doc.format, "text/plain")                         as format,
   doc.url                                                    as url,
   COLLECT(COALESCE(category.category, ""))                   as categories

(untested query)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM