Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does neo4j have a "trigger" mechanism via Cypher? (similar to percolators in ElasticSearch)

Tags:

neo4j

cypher

I am looking for a method to store cypher queries and when adding nodes and relations be notified when it matches said query? Can this be done currently? Something similar to ElasticSearch percolators would be great.

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-percolate.html

like image 245
Tim Avatar asked Dec 10 '14 18:12

Tim


People also ask

What is the purpose of the Neo4j Cypher tool?

Cypher is Neo4j's graph query language that lets you retrieve data from the graph. It is like SQL for graphs, and was inspired by SQL so it lets you focus on what data you want out of the graph (not how to go get it).

What schema objects are used in a Neo4j database?

Schema. A schema in Neo4j refers to indexes and constraints. Neo4j is often described as schema optional, meaning that it is not necessary to create indexes and constraints. You can create data — nodes, relationships and properties — without defining a schema up front.

Which clause is used to search the data with a specified pattern in Neo4j?

The MATCH clause allows you to specify the patterns Neo4j will search for in the database.


1 Answers

Update

The answer below was accurate in 2014. It's mostly accurate in 2018.

But now there is a way of implementing triggers in Neo4j provided by Max DeMarzi which is pretty good, and will get the job done.

Original answer below.

No, it doesn't.

You might be able to get something similar to what you want by using a TransactionEventHandler object, which basically lets you bind a piece of code (in java) to the processing of a transaction.

I'd be really careful with running cypher in this context though. Depending on what kind of matching you want to do, you could really slaughter performance by running that each time new data is created in the graph. Usually triggers in an RDBMS are specific to inserts or updates on a particular table. In Neo4J, the closest equivalent you might have is on creating/modifying a node of a certain type of label. If your app has any number of different node classes, it wouldn't make sense to run your trigger code whenever new relationships/nodes are created, because most of the time the node type probably wouldn't be relevant to the trigger code.

Related reading: Do graph databases support triggers? and a feature request for triggers in neo4j

like image 142
FrobberOfBits Avatar answered Oct 23 '22 11:10

FrobberOfBits