Wildcard search with cypher query and spring neo4j - neo4j

When I execute the below query in neo4j console, i get the correct result set.
start n=node:search('username:*') return n.username;
I am using spring data neo4j in my java web app.
In the repository code, i defined query as:
#Query("START n=node:search({0}) RETURN n.name as name, n.username as username
Parameter passed
{0} = 'username:*'
There is no exception but the result set size is 0.
Can you please help me resolve the issue?

Unfortunately, the whole lucene query cannot be a parameter in Cypher, as far as I know. You'll need to resort to string concatenation/interpolation, probably. Similar to the issue I posted about relationship types as parameters: https://github.com/neo4j/neo4j/issues/340

Related

How to find a node quick in Neo4J 3.3.9 - cypher query optimization

I have the following Neo4J DB model:
I need to be able to find a node of the type Concept called "idea" made by the user infranodus and see which nodes of the type Context it is connected to.
I use the following query, but it's taking too long and doesn't even load...
MATCH (ctx:Context)-[:BY]->(u:User{name:'infranodus'})
WITH DISTINCT ctx
MATCH (c:Concept{name:'idea'})-[:AT]->(ctx)<-[:AT]-(cn:Concept)
RETURN DISINCT c, ctx, count(cn);
How to fix it?
adding indexes to the neo4j database would be helpful ( i didnt see any there ) then start your match with the indexed node and traverse from there. i think that having a
MATCH (c:Concept{name:'idea'})-[:AT]->(ctx)<-[:AT]-(cn:Concept)
WHERE (ctx)-[:BY]->(u:User{name:'infranodus'})
....
would also avoid querying twice.
Create an index on the name property of nodes with the User label - a unique index would be great for this.
An index for the name property on concept would be good, too (probably without uniqueness constraint - even though you're looking for distinct nodes explicitly).
Start your query from there.
MATCH (u:User {name:'infranodus'})
MATCH (c:Concept {name: 'idea'})
MATCH (u)<-[:BY]-(ctx:Context)<-[:AT]-(c)
MATCH (c:Concept{name:'idea'})-[:AT]->(ctx)<-[:AT]-(cn:Concept)
RETURN c, ctx, size((c)-[:AT]->(ctx)<-[:AT]-(:Concept))
Doesn't look as nice, but you're asking for query tuning. Make sure to PROFILE your existing query and this. Plus, you had a typo in your query after your return keyword.

Cypher Where IN ['GUID', 'GUID'] in Neo4j

I am trying to find nodes in Neo4j Db by Guid from my object.
I have 'Id' field in my object, which is Guid.
Need to find several nodes by those Guid Id, but when I use Where clause and use IN command with array of Guid Id's I get response, that (no changes, no records)
MATCH (n) WHERE n.Id IN ['44BEE918-507A-15C6-0950-0017D4A12234', 'BC2D286F-0B73-6926-B01D-27C8F0EA919D'] RETURN n LIMIT 25
I tried to pass Guids without quotes and with double quotes, but it didn't help.
When I pass the Name of those nodes it works perfect.
What I am doing wrong?
I found an issue.
The problem was with case sensitivity. Means my Guid in the database looks like '44bee918-507a-15c6-0950-0017d4a12234', but I tried to find in upper case.

Neo4j / Cypher Query using withinDistance returns 0 rows

I've just set the Neo4j Spatial plugin on my server and I'm using SDN 3.1.2 to create my wkt index:
#Indexed(indexName = "CarsLocation", indexType = IndexType.POINT) var wkt: String
The whole works great and I can make queries involving withinDistance using the HTTP console like this, returning my matched node:
POST /db/data/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance {"layer":"CarsLocation","pointX":48.892501,"pointY":2.373140,"distanceInKm":100.0}
However, I want to query using Cypher like this:
start n = node:CarsLocation("withinDistance:[48.892501,2.373140,100.0]") return n
It just returns 0 rows, no matter the values are.
I came across this post, advising to manually add the Car node to the spatial index: CarsLocation.
So I executed this command:
POST /db/data/index/node/CarsLocation {"value":"dummy","key":"dummy", "uri":"http://localhost:7474/db/data/node/30"} //30 being the Car node I want to index
but it also doesn't make the cypher query works.
I also try executing Cypher through an http call:
POST /db/data/cypher {"query" : "start n = node:CarsLocation({indexQuery}) return n", "params": {"indexQuery": "withinDistance:[48.892067, 2.373140, 10.0]"}}
Doesn't work either.
However, when I specify a huge amount of kilometers (IMO exceeding the limit), this one passes:
start n = node:CarsLocation("withinDistance:[48.892501,2.373140,10000.0]") return n
(Returning my Car node 30).
Did I miss something important?
I don't figure out where could be the mistake, preventing Cypher query to work.
I'm pointing out I'm using Neo4j 2.1.2.
Mik378,
The problem here is pretty simple. The 'withinDistance' Cypher spatial index query has a quirk (a bug, as far as I'm concerned). You must specify latitude first, then longitude. I'm not familiar with SDN, so I don't know if you also need to do the explicit spatial index creation commands.
Grace and peace,
Jim

Identifying parameters of Cypher query

Is there an API for identifying the named parameters of a given Cypher query? When taking the following query as example:
MATCH (n) WHERE n.firstName = { name } AND n.LastName = { lastName } RETURN n
Then this API should return "name" and "lastName".
Does Neo4j provide such an API or would I have to manually parse the query string to identify any parameters it contains?
There is no API for obtaining the names of the properties used in a Cypher query. There is generally no need for such a utility, since the code making the query should already know that information.
Maybe you can begin your query with parameters in a transaction, get the result/errors and rollback it ?
http://docs.neo4j.org/chunked/stable/rest-api-transactional.html

What is the appropriate cypher query?

I am trying to run the web ui on
7474/webadmin/#
Suppose I want to find a node that has a property "title" with a value of "Home".
How do I find that node using a cypher query? (There should be only one node.)
Also, suppose I want to retrieve a relationship?
Let's say I have the following:
A -entitledTo-> B -entitledTo-> C
I have already tried the following:
start n=node(*) where n.title='Home' return n;
start c=node(node_c_id) match a-[:entitledTo]->b-[:entitledTo]->c return a,b,c;
However, I get this error message: The property 'title' does not exist on Node[0]
How do I resolve this issue?
Lastly, this is version 2.0.0-M03
use:
start n=node(*) where has(n.title) and n.title='Home' return n
In general you should consider using indexes for this kind of operation, Neo4j's reference manual has lots of information about this.
You can use:
start n=node(*) where n.title! ='Home' return n;
See the section on missing properties in where clauses
To retrieve the Relationships, perhaps the Cypher PATH command could be usefull.

Resources