marcelo
marcelo

Reputation: 225

neo4jclient ill formed cypher request sent to server

Trying to execute the following cypher query (which executes ok from neoclipse)

START a=node(*)   MATCH a-[:Knows]->p   WHERE (p.Firstname! = "Steve" )   RETURN p

from neo4jclient with the following statement

protected void Populate()
    {
        var client = new GraphClient(new Uri("http://altdev:7474/db/data"));
        client.Connect();

        var query = client.Cypher
            .Start(new RawCypherStartBit("all", "node(*)"))
            .Match("all-[:Knows]->p")
            .Where((Person p) => p.Firstname == "Steve")
            .Return<Node<Person>>("Person");

        var people = query.Results;
 }

the client throws an exception, as follows

The query was: START all=node(*)
MATCH all-[:Knows]->p
WHERE (p.Firstname! = {p0})
RETURN Person

The response status was: 400 Bad Request

The response from Neo4j (which might include useful detail!) was: {
  "message" : "Unknown identifier `Person`.",
  "exception" : "SyntaxException",
  "fullname" : "org.neo4j.cypher.SyntaxException",
  "stacktrace" : [ "org.neo4j.cypher.internal.symbols.SymbolTable.evaluateType(SymbolTable.scala:59)", "org.neo4j.cypher.internal.commands.expressions.Identifier.evaluateType(Identifier.scala:47)", "org.neo4j.cypher.internal.commands.expressions.Expression.throwIfSymbolsMissing(Expression.scala:52)", "org.neo4j.cypher.internal.pipes.ColumnFilterPipe$$anonfun$throwIfSymbolsMissing$1.apply(ColumnFilterPipe.scala:61)", "org.neo4j.cypher.internal.pipes.ColumnFilterPipe$$anonfun$throwIfSymbolsMissing$1.apply(ColumnFilterPipe.scala:61)", "scala.collection.immutable.List.foreach(List.scala:309)", "org.neo4j.cypher.internal.pipes.ColumnFilterPipe.throwIfSymbolsMissing(ColumnFilterPipe.scala:61)", "org.neo4j.cypher.internal.pipes.PipeWithSource.<init>(Pipe.scala:63)", "org.neo4j.cypher.internal.pipes.ColumnFilterPipe.<init>(ColumnFilterPipe.scala:30)", "org.neo4j.cypher.internal.executionplan.builders.ColumnFilterBuilder.handleReturnClause(ColumnFilterBuilder.scala:60)", "org.neo4j.cypher.internal.executionplan.builders.ColumnFilterBuilder.apply(ColumnFilterBuilder.scala:38)", "org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl.prepareExecutionPlan(ExecutionPlanImpl.scala:54)", "org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl.<init>(ExecutionPlanImpl.scala:36)", "org.neo4j.cypher.ExecutionEngine$$anonfun$prepare$1.apply(ExecutionEngine.scala:80)", "org.neo4j.cypher.ExecutionEngine$$anonfun$prepare$1.apply(ExecutionEngine.scala:80)", "org.neo4j.cypher.internal.LRUCache.getOrElseUpdate(LRUCache.scala:37)", "org.neo4j.cypher.ExecutionEngine.prepare(ExecutionEngine.scala:80)", "org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:72)", "org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:76)", "org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:79)", "org.neo4j.server.rest.web.CypherService.cypher(CypherService.java:94)", "java.lang.reflect.Method.invoke(Method.java:616)", "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)" ]
}

As you can see, essentially the queries are the same. And the nodes I'm trying to get are of _type "Person"

TIA

Marcelo

Upvotes: 1

Views: 164

Answers (3)

Tatham Oddie
Tatham Oddie

Reputation: 4290

In your MATCH clause you use the identity p:

.Match("all-[:Knows]->p")          // becomes MATCH all-[:Knows]->p

In your RETURN clause you change to using the identity Person:

.Return<Node<Person>>("Person");   // becomes RETURN person

You need to pick one and be consistent.

Integrating some other clean up too, your full query should be:

   var query = client.Cypher
        .Start(new { all = All.Nodes })
        .Match("all-[:Knows]->p")
        .Where((Person p) => p.Firstname == "Steve")
        .Return<Person>("p");

Upvotes: 1

Charlotte Skardon
Charlotte Skardon

Reputation: 6270

It's down to the way you are creating the Cypher code, specifically what you are returning:

var query = client.Cypher
    .Start(new RawCypherStartBit("all", "node(*)"))
    .Match("all-[:Knows]->p")
    .Where((Person p) => p.Firstname == "Steve")
    .Return<Node<Person>>("p"); // <-- THIS LINE SHOULD SAY 'P' NOT 'Person'

The return statement requires the name to be the same as the node you have defined. So you use: all-[:knows]->p where you define p. Now you need to return it.

(Which is what Peter is saying in his answer :))

Upvotes: 0

Peter Neubauer
Peter Neubauer

Reputation: 6331

You are trying to return a Person node that is not assigned to anything in the query.

Upvotes: 0

Related Questions