philippkueng / node-neo4j

Neo4j REST API wrapper for Node.js
MIT License
211 stars 44 forks source link

Cypher query returing null data #29

Closed ctippur closed 10 years ago

ctippur commented 10 years ago

Phil

Sorry to bug you again.

I am not sure if I am doing anything wrong but the below query on graphenedb results with the right data:

n = node:global_category_index('name:"test4" AND type:"test_category" ') return n

results in

name test4 type test_category cr_date 2013-12-24T19:01:52.904Z last_upd 2013-12-24T19:01:52.904Z

However, when I use db.cypherQuery(cypherQuery, function(err, result) ...

I get no data.

2013-12-29T18:33:22.657726+00:00 app[web.1]: RESULT OF CYPHER QUERY 2013-12-29T18:33:22.659600+00:00 app[web.1]: { columns: [ 'n' ], data: [] }

Can you please take a look?

philippkueng commented 10 years ago

Hi Shekar,

Not sure wether it's a bug or not. With your query above n = node:global_category_index('name:"test4" AND type:"test_category" ') return n you had some ' in there. Are they truly needed, because that might be what causes the error. Could you paste the code you used with db.cypherQuery("n = node:global ...") just so i can understand the problem a little better and help fix the problem.

Have a nice evening and thanks for pointing that out, might really be an issue.

Cheers Phil

ctippur commented 10 years ago

Here is the code ..

var checkElementExists = function checkElementExists (cypherQuery,node, index_name, cb) { console.log("Cypher query .. "); console.log(cypherQuery); try { db.cypherQuery(cypherQuery, function(err, result){ console.log("RESULT OF CYPHER QUERY"); console.log(result); if (! result){ cb("Error while checking if element exists ",{"data": {"id": null, "status": 1, "response":"maybe the index is missing in cypher query .. " + cypherQuery + " Error returned .. " + err}}); }else if (result.data.length === 0){ var now = new Date(); var jsonDate = now.toJSON(); node.cr_date=jsonDate; node.last_upd=jsonDate; } }

philippkueng commented 10 years ago

Thanks, but what does console.log(cypherQuery); print out? Can you give me that string as it appears in the log.

On Sunday, December 29, 2013, ctippur wrote:

Here is the code ..

var checkElementExists = function checkElementExists (cypherQuery,node, index_name, cb) { console.log("Cypher query .. "); console.log(cypherQuery); try { db.cypherQuery(cypherQuery, function(err, result){ console.log("RESULT OF CYPHER QUERY"); console.log(result); if (! result){ cb("Error while checking if element exists ",{"data": {"id": null, "status": 1, "response":"maybe the index is missing in cypher query .. " + cypherQuery + " Error returned .. " + err}}); }else if (result.data.length === 0){ var now = new Date(); var jsonDate = now.toJSON(); node.cr_date=jsonDate; node.last_upd=jsonDate; } }

— Reply to this email directly or view it on GitHubhttps://github.com/philippkueng/node-neo4j/issues/29#issuecomment-31325104 .

ctippur commented 10 years ago

n = node:global_category_index('name:"test4" AND type:"test_category" ') return n

Thats the query..

freeeve commented 10 years ago

You seem to be lacking a "start" at the beginning.

ctippur commented 10 years ago

Sorry .. Here is the query...

start n = node:global_category_index('name:"test4" AND type:"global_category" ') return n

freeeve commented 10 years ago

Can you give us the code where you call checkElementExists (and where you define the parameters).

ctippur commented 10 years ago

I was not sure if there was a way to create a unique node. Here is the code that creates the cypher query and calls checkElementExists.

var addElement=function addElement (node,res, cb) {

//cypher query to chwck if the node is available
var cypherQuery="start n = node:";

// Check index name
var index_name =  node.type + '_index';
cypherQuery+= index_name + "('";
// Iterate thro the node and and append the cypher query
for (var key in node)   {
    //start n = node:category_index('type:category OR key:456') return n
    if (key === 'type' || key === 'name'){
       cypherQuery +=  key + ":\"" + node[key] + "\" AND ";
    }
    //insertIndex(node,node._id,index_name, key, node.data[key], cb );
}
cypherQuery=cypherQuery.replace(/AND $/,'');
cypherQuery+="') return n";
console.log("CYPHER query to add element " + cypherQuery);
// Call check element to see if the node exists. If the node exists, then update, if not, create a new one.
checkElementExists(cypherQuery,node, index_name, cb);

};

ctippur commented 10 years ago

Any updates please?

philippkueng commented 10 years ago

Hi @ctippur was offline for the past couple of days. will have time at around 4 tonight. Will keep you posted.

philippkueng commented 10 years ago

Hi Shekar,

I'm having difficulties reproducing your scenario. Could you give me a cypher query to produce that dataset so that the query returns the data as described in your issue. Also i'm philipp.kueng on skype if you need more realtime-ish help.

Sorry for the delay the last couple of days. Was on vacation.

ctippur commented 10 years ago

Phil - Here is the cypher query.. start n = node:global_category_index('name:"test4" AND type:"global_category" ') return n

I will add you on to my skype id.

philippkueng commented 10 years ago

Hi Shekar,

Was wondering wether the issue still exists? or wether you could solve it now with the new Cypher query features? Please let me know so we can close this issue.

To anyone else reading this, the issue has most likely something to do with Neo4j legacy indexing. Which doesn't index by default. So whenever a node with an index is getting inserted it takes a certain time for it to be searchable via the index. The default indexing is disabled with both heroku and the standalone Neo4j installation. It can however be turned on, on GrapheneDB afaik. Since Neo4j no longer supports those legacy indexes and Shekar is building something new, I suggested going with the updated Cypher query functionality in Neo4j 2.0.0 which enables greater flexibility when working with indexes and offers more stuff on top too. There's a great talk explaining all the new things over here https://vimeo.com/82319888