Neo4j cypher how to delete empty relations - neo4j

I have five relationships in the database, all created in the past. Four are empty, not attached to any node. How can I delete them? I want to keep only the one I am currently using and is attached to the nodes.

Neo4j does not offer a direct way to get rid of labels or relationship types that are no longer in use. However you can use the batch inserter API as a offline tool to copy over the contents of your db into a fresh one.
Luckily Michael has already written a tool doing this, check out https://github.com/jexp/store-utils. Be sure to bump the Neo4j version in pom.xml to the one you're currently using.

It seems that this is a problem with one single radical solution so far: to erase physically the database folders and files. Which I don't like it at all.

Related

Creating many relationships in one script

I am a relative newbie to the world of cypher programming, and therefore hoping for a solution to this problem from the experts community here.
I am creating a graph from an excel file, which contains different categories, items and so on. One item can belong to multiple categories and so on.
I have generated the relevant create relationship statements (there are about 200 of them). However, when i put them through neo4j browser, the interface complains that i can only run one match - create command at a time.
i am not using any other programming language or their API and simply using neo4j browser to achieve this.
Kindly suggest path forward.
my env : neo4j desktop 4.1.3 on Windows 10 Enterprise.
apoc plugin is enabled, but i m not using it yet.
Thanks
raghav
By default, Neo4j Browser only allows one Cypher statement to be executed at a time. This can be changed by going to the browser settings on the sidebar (gear icon), and then checking the Enable multi statement query editor checkbox. Afterward, you should be able to execute multiple Cypher statements on the query editor.

Neo4j to grafana

I want to present release data complexity which is associated with each node like at epic, userstory etc in grafana in form of charts but grafana do not support neo4j database.Is there any way Directly or indirectly to present neo4j database in grafana?
I'm having the same issues and found this question among others. From my research I cannot agree with this answer completely, so I felt I should point some things out, here.
Just to clarify: a graph database may seem structurally different from a relational or time series database, but it is possible to build Cypher queries that basically return graph data as tables with proper columns as it would be with any other supported data source. Therefore this sentence of the above mentioned answer:
So what you want to do is just not possible.
is not absolutely true, I'd say.
The actual problem is, there is no datasource plugin for Neo4j available at the moment. You would need to implement one on your own, which will be a lot of work (as far as I can see), but I suspect it to be possible. For me at least, this will be too much work to do, so I won't use any approach to read data directly from Neo4j into Grafana.
As a (possibly dirty) workaround (in my case), a service will regularly copy relevant portions of the Neo4j graph into a relational database (or a time series database, if the data model is sufficiently simple for that), which Grafana is aware of (see datasource plugins), so I can query it from there. This is basically the replication idea also given in the above mentioned answer. In this case you obviously end up with at least 2 different database systems and an additional service, which is not so insanely great, but at the moment it seems to be the quickest way to resolve the problem with the missing datasource plugin. Maybe this is applicable in your case, too.
Using neo4j's graphite metrics you can actually configure data to be sent to grafana, and from there build whichever dashboards you like.
Up until recently, graphite/grafana wasn't supported, but it is now (in the recent 3.4 series releases), along with prometheus and other options.
Update July 2021
There is a new plugin called Node Graph Panel (currently in beta) that can visualise graph structures in Grafana. A prerequisite for displaying your graph is to make sure that you have an API that exposes two data frames, one for nodes and one for edges, and that you set frame.meta.preferredVisualisationType = 'nodeGraph' on both data frames. See the Data API specification for more information.
So, one option would be to setup an API around your Neo4j instance that returns the nodes and edges according to the specifications above. Note that I haven't tried it myself (yet), but it seems like a viable solution to get Neo4j data into Grafana.
Grafana support those databases, but not Neo4j : Graphite, InfluxDB, OpenTSDB, Prometheus, Elasticsearch, CloudWatch
So what you want to do is just not possible.
You can replicate your Neo4j data inside of those database, but the datamodel is really different ... (timeseries vs graph).
If you just want to have some charts, you can use Apache Zeppeline for that.

Neo4j favorite queries list

I create several neo4j databases for several demo projects on my laptop.
When I open any of my projects I can see ALL the queries I created for ALL projects.
How can I split that any query will be viewed only from the DB it belongs too?
Thanks Tal
If you have a single DB, then keeping your "logical subgraphs" apart when doing queries requires crafting your data model so that each subgraph can be queried independently of the others.
A typical approach would be to use specific node labels for each subgraph, and to not share those labels between subgraphs. If you do that, then your queries can specify that you only care about the nodes with those labels.
A more exact answer would depend on your actual use cases.
Thanks for your answers.I figure it up.
For each database, I should configure a separate PORT.
Since all my databases refer to One port 7474 the queries from all the databases were mixed together.
Tal

Load Entire Neo4j Database into Linkurious's SigmaJS

How can I load an entire Neo4j database into Linkurious's SigmaJS Graph API? On that page, I don't see any methods that describe how to import a database in its entirety -- only how to build out a graph manually by adding nodes and edges. I suspect that the read() function almost does what I want (reading in an object), but it is unclear in what format I must supply this object in.
It would be great to be able to simply pass in the graph.db folder within my Neo4j folder.
I think you've got the idea of the library correct. It's a general purpose library to display graph visualizations and not specific to any graph database. I also suspect that it's not going to effectively hold your entire database (it depends on the size). The idea of it is to load in the required subset of the data and make it easy to display and work with that data.
The linksurious team could correct me if I'm wrong here, though ;)

How to load relational database tables into neo4j database

I have tables which have millions of records. I need to load these records as nodes in neo4j.
Please help me out on how to do it as I'm new to neo4j.
It is quite easy, just map your entities that should become nodes into a set of csv files and the connections that should become relationships in another set of files.
Then run them with my batch-importer: https://github.com/jexp/batch-import/tree/20#binary-download
import.sh nodes1.csv,nodes2.csv rels1.csv,rels2.csv
Add types and index information to the headers and the batch.properties config file as needed.
You can use the batch-importer for the initial inserter but also subsequent updates (but the database has to be shut-down for that).
It is pretty easy to connect to your existing database using its driver and then extract the information of the right shape and kind and insert it into your graph model,
Either using Cypher statements with parameters or the embedded, transactional Java API for ongoing updates.
See: http://jexp.de/blog/2013/05/on-importing-data-in-neo4j-blog-series/
You can export to CSV and import it into node (probably wont work well since you have millions of records)
You can write a program to do it (this is what I am currently working on).
This also depends on what programming languages you know... but the bottom line is, because no two databases are created equally (unless on purpose), it's very difficult to create a catch-all solution for migrating data from SQL to Neo.
The best way that I've discovered so far is to create a program that queries the tables in the database, finds all related tables (i.e. foreign keys), and imports all those table rows into Neo, labeling the nodes using the Table name, then process the foreign keys as relationships.
It's not easy. I've been working on something for my database here for a week or so now... but I'm close!

Resources