EzDevInfo.com

neography

A thin Ruby wrapper to the Neo4j Rest API

parameterized Cypher query not working in Neography

Trying to execute a parameterized Cypher query with Neography v0.0.23.

Even though the non-parameterized version works:

Neo.execute_query("start n=node(3) return n")
 => {"data"=>[[{....

The parameterized version doesnt work:

Neo.execute_query("start n=node(id) return n", {:id => 3})
 => nil 

Source: (StackOverflow)

Neography: Traversal vs. Cypher

Im currently building something with Neo4j and Neography and were wondering what is preferred: Using the traverse method or a Cypher query?

Personally, I like Cypher, but I have no idea which is better/more performant


Source: (StackOverflow)

Advertisements

Neography and Rails

I am experimenting using Neography with Rails 3 and can't quite understand where to specify DB connections, Model Validations (validates_presence_of) etc. The examples available for Neography does not have one for Rails. Would appreciate any pointers.


Source: (StackOverflow)

Neography and Neo4j dilemma

I'm trying to implement a rails application with neo4j. For hosting I found that Heroku supports neo4j REST (public beta). Looking for gems I found neography and neo4j.

I started with neo4j and didn't find support for REST. Is it possible to work with REST? Is there any benefits to go with embedded database?

If I go with neography, can gems like devise be used in the project?


Source: (StackOverflow)

slow neo4j cypher query

I'm trying to find out why my cypher query is running so slow (2-5 seconds for only 5000 nodes). The query is trying to find all the jobs the a profile can reach inside his network (a job the his friends or his friends of friends work in the same company)

This is the query :

Start current_profile= node:node_auto_index(neoid_unique_id = "Profile:1")
 Match current_profile-[r:friendships*0..2]->friends-[:roles]->company-[:positions]->jobs
 return distinct company.fmj_id

I tried trimming down the query to see what I'm doing wrong and even this simple query takes too long:

START root=node(0)
Match root-[:job_subref]->j-[:jobs]->jobss
return jobss

Am I doing anything wrong?

I'm using neoid that is based on neography gem


Source: (StackOverflow)

Neo4j console.log file

I am experiencing something strange: my console.log is filled with messages like this:

DONE:0
Got Location:http://localhost:8474/db/data/index/node/<index-name>/<property-name>/<property-value>/<some int value>
DONE:1
DONE:2
DONE:0
Got Location:http://localhost:8474/db/data/index/node/<index-name>/<property-name>/<property-value>/<some int value>
DONE:1
DONE:2
Got Location:http://localhost:8474/db/data/index/node/<index-name>/<property-name>/<property-value>/<some int value>
DONE:3
Got Location:http://localhost:8474/db/data/index/node/<index-name>/<property-name>/<property-value>/<some int value>
DONE:4
Got Location:http://localhost:8474/db/data/index/node/<index-name>/<property-name>/<property-value>/<some int value>
DONE:5
Got Location:http://localhost:8474/db/data/index/node/<index-name>/<property-name>/<property-value>/<some int value>

It's quite annoying, as the file grew to 1G in two days. These look like debug messages, but I can't find the culprit.

I am using Neo4j 1.9, gremlin plugin 1.5, neography 1.0.9


Source: (StackOverflow)

neo4j : batch import relations

I'm having trouble to import relationships in a graph.

Let's say I have a few hundreds unique,indexed users that are already created. Then I'd like to create about 120k nodes, each of them being linked to some user through a relationship.

Unfortunately, I'm unable to find a way to batch the import. I'm trying to perform this with the neography ruby gem, but as I'm very new with this environment I wouldn't mind using another way if needed.

What I tried :

@neo.batch(
  [:get_node_index, 'user', 'user_id', '1'], #attempt to get the node from index
  [:create_node, {"foo => 'bar'}],
  [:create_relationship, "has" , "{0}", "{1}"] 
) # => fails

,

@neo.batch(
  [:create_unique_node, "user", "user_id", "1"], #attempt to create or get the node
  [:create_node, {"foo" => "bar"}],
  [:create_relationship, "has", "{0}", "{1}"]
) # => fails. 

Please note that it is nonetheless possible to batch some create_unique_node commands alone.

The only way I could get the script run is to use

@neo.batch(
  [:create_node, {"user_id" => 1}], #works, but duplicates the node
  [:create_node, {"foo" => "bar"}],
  [:create_relationship, "has", "{0}", "{1}"]
) # => success

However, this will duplicate all my user nodes, which definitely not what I want to achieve. It seems my question is similar to this one, however I don't get at all how am I supposed to use the index when creating the relationships.

Any help would be much appreciated, thanks in advance


Source: (StackOverflow)

Arrays in NEO4j using Neography+Heroku

I am running a rake process that imports my data into Neo4j. It's all fine until arrays come up. Here's a sample:

{:spelling=>"the", :letters=>["T","H","E"], :length=>2, :rank=>1, :part_of_speech=>"article"}

Here's the ruby code for importing it that fails:

node = @neo.create_unique_node("words", "spelling_phonemes", a[:spelling]+','+a[:phonemes], {"spelling" => a[:spelling], "length" => a[:length], "letters" => a[:letters].split(','), "rank" => a[:rank], "part_of_speech" => a[:part_of_speech]})

Here's the error: Unknown property type on: [T, H, E], class java.util.ArrayList

It's working fine on locally. What gives! From reading around, it seems likes ArrayList might be the issue as only type Array works. If that's the case, how do I ensure that the ruby array is casted/converted properly as a Java Array ?! Thanks!

Also, using neo4j 2.0 locally and Heroku is 1.8.1 I think.


Source: (StackOverflow)

R14 Memory quota exceeded on Heroku for background job running with Sidekiq

We're running sidekiq workers that utilize neography to do batch operations.

Our batch array holds up to 400 operations before flushing (we've tried lower numbers as well).

We hit the R14 memory error on heroku and things grind to almost a halt, so we suspect a memory leak of some sort ( I have already check for bloat ). However, we've been unable to figure out where it is or how to prevent it.

We've tried to use all debugging memory gem as ruby-prof, [...] without any results or clues, read object counts via ObjectSpace and even trying to debug line by line and launch the process without a background job but just via the rails c and the following command to monitor the memory usage top -pid `ps auw | grep -i 'rails c' | head -n 1 | awk '{print $2}'` -stats RSIZE.

I tried to update our ruby version to the latest (2.1.0) but no changes.

Any idea are welcome to help us to make our workers happier !


Source: (StackOverflow)

Neo4j Batch Inserts

I used the Neo4j API to batch insert a few million records, which normally would take much longer if done individually. The import finished considerably faster but I do not see the millions of records I inserted. Does Neo4j keep some form of queue for the batch insertions and insert it over time?

If so, how can I see the progress of this queue? I am doing a count and I notice the records are increasing, but at a very slow pace.

I am using the Neography gem's batch insertion (https://github.com/maxdemarzi/neography/wiki/Batch) and the code that does the batch insert is below:

User.find_in_batches(batch_size: 500) do |group|
   $neo4j.batch(*group.map { |user| ["create_unique_node", "users", "id", user.id, user.graph_node_properties] })
end

Running Neo4j 2.1.2 enterprise edition on Ubuntu 12.04 LTS.


Source: (StackOverflow)

Where put Neography Rest wrapper in rails

I have a bunch of functions in my controller that help me access Neo4j through the Neography::Rest function but I want to move it into its own class.

Where can I put it so I can call Neo.blabla inside any controller like a Model? I tried to put it with the Models but it does not find the class. There should be an easy solution that loads one instance of that class so in my application I can access the Rest connection from any controller. I am quite sure putting the @neo inside the controller is not how one is supposed to do it.

My neo4j graph is too complicated to use the Neo4j ActiveNode stuff. It really wouldn't help me. I just need the Neography REST access and access my own wrapper on top of that.


Source: (StackOverflow)

How to use "MATCH.. CREATE UNIQUE.." with neography

I'm trying to write an importer script that will take a MySQL resultset and add nodes and relationships in my Neo4J DB. To simplify things, my resultset has the following fields:

  • application_id
  • amount
  • application_date
  • account_id

I want to create a node with Application label with the application_id, amount, application_date fields and another node with Account label with account_id field and a relationship between them.

My SQL query is from the applications table so I'm not afraid of dups there, but an account_id can appear more than once and I obviously don't want to create multiple nodes for that.

I'm using neography (but willing to switch if there is something simpler). What would be the best (easiest) way to achieve that? My script will drop the database before it starts so no leftovers to take care of.

Should I create an index before and use create_unique_node?
I think I can do what I want in cypher using "MATCH .. CRAETE UNIQUE..", what's the equivalent of that in neography? I don't understand how index_name gets into the equation...
Should I or should I not define the constraint on Account?

Many thanks, It's my first time with graph DBs so apologies if I miss a concept here..


Source: (StackOverflow)

Ways to remember and reuse previous query result in Neo4j

I am coding in Ruby using Neo4j with the gem Neography. When doing query, I use the method execute_neo4j_query provided by Neography. I am not sure about the best practice.

Suppose I use following code to fetch a user:

user1 = @neo.execute_neo4j_query("
      MATCH (user:User {user_id: '#{params[:user_id_1]}'})
      RETURN id(user)
      LIMIT 1
      ")

and to fetch another user similarly

user2 = @neo.execute_neo4j_query("
      MATCH (user:User {user_id: '#{params[:user_id_2]}'})
      RETURN id(user)
      LIMIT 1
      ")

Then I did some stuff with this two users.

Now I need to create an edge between this two users, so I did this

@neo.execute_neo4j_query("
      MATCH (user1:User {user_id: '#{params[:user_id_2]}'})
      MATCH (user2:User {user_id: '#{params[:user_id_2]}'})
      CREATE UNIQUE (user1)-[:FOLLOW]->(user2)
      ")

However, I believe such approach is not optimal, since I queried for the same two users twice.

My question is:

1) Is there a way to reuse previously queried results using Neography?

2) Is it recommended to use methods provided by Neography such as @neo.create_node other than using execute_neo4j_query directly? I choose the latter because I am not sure if the encapsulated methods can satisfy my task. So, if you can rewrite my above codes in native Neography code, it will be greatly appreciated.


Source: (StackOverflow)

Reading lots of csv data into neo4j using execute_query, ruby and neography

I wrote a quick ruby routine to load some very large csv data. I got frustrated with various out of memory issues trying to use load_csv so reverted to ruby. I'm relatively new to neo4j so trying Neography to just call a cypher query I create as a string.

The cypher code is using merge to add a relationship between 2 existing nodes:

cmdstr=match (a:Provider {npi: xxx}),(b:Provider {npi:yyy}) merge (a)-[:REFERS_TO {qty: 1}]->(b);

@neo.execute_query(cmdstr)

I'm just looping through the rows in a file running these. It fails after about 30000 rows with socket error "cannot assign requested address". I believe GC is somehow causing issues. However the logs don't tell me anything. I've tried tuning GC differently, and trying different amounts of heap. Fails in the same place everytime. Any help appreciated.

[edit] More info - Running netstat --inet shows thousands of connections to localhost:7474. Does execute_query not reuse connections by design or is this an issue?

I've now tried parameters and the behavior is the same. How would you code this kind of query using batches and make sure you use the index on npi?


Source: (StackOverflow)

How to limit results from neo4j traversal with neography

Apologies if this is a simple question, but I turn to the wisdom of SO to get me over this bump :)

I'm using RoR 3.1.1 with the neography gem.

I currently have a neo4j graph of people nodes with relationships as "friends" connecting them. Given a specific person's node, I'd like to page through results of their friends-of-friends (2nd degree nodes) 5 at a time. Right now, I use the following traversal code which gets me ALL of the friends-of-friends at once (it can take so long that it will cause a timeout):

    nodes = @neo.traverse(user_node,"nodes", {"order" => "breadth first",
                                          "uniqueness" => "node global",
                                          "relationships" => {"type"=> "friends", "direction" => "all"},
                                          "return filter" => {
                                            "language" => "javascript",
                                            "body" => 
                                            "position.length() == 2;"},
                                          "depth" => 2}) 

From the neo4j website (http://docs.neo4j.org/chunked/stable/rest-api-traverse.html#rest-api-creating-a-paged-traverser), it looks like there is already such a thing as paged traversals, but I don't see any references to doing this from neography.

Could someone provide example code to show how to do this with neography if possible, how to do it without neography if necessary, or a work-around such as limiting the number of results returned from the example traversal I'm already doing? Thanks!


Source: (StackOverflow)