0
votes

As mentioned here,

http://neo4j.com/docs/stable/transactions-events.html

Transaction Event listeners execute in an unpredictable sequence.

I'd like to assign a UUID on an entity before pushing it to Elastic Search, and have that field indexed, instead of the default @GraphId of neo4j, which was specifically described as bad practice, which I understand why the neo4j UUID plugin was made.

These are the 2 documented plugins for neo4j that I'm trying to use to achieve that.

https://github.com/neo4j-contrib/neo4j-elasticsearch https://github.com/graphaware/neo4j-uuid

A sample neo4j.properties configuration would be:

#elasticsearch plugin
elasticsearch.host_name=http://localhost:9200
elasticsearch.index_spec=persons:Person(uuid,name)
#uuid plugin
com.graphaware.module.UIDM.uuidProperty=uuid 

By trying to create a Person node, I get an exception with the following trace

   Caused by: org.neo4j.kernel.api.exceptions.TransactionHookException: Transaction handler failed.
    at org.neo4j.kernel.impl.api.TransactionHooks$TransactionHooksState.add(TransactionHooks.java:100)
    at org.neo4j.kernel.impl.api.TransactionHooks.beforeCommit(TransactionHooks.java:59)
    at org.neo4j.kernel.impl.api.KernelTransactionImplementation.commit(KernelTransactionImplementation.java:512)
    ... 37 more
Caused by: org.neo4j.graphdb.NotFoundException: NODE[2] has no property with propertyKey="uuid".
    at org.neo4j.kernel.impl.core.NodeProxy.getProperty(NodeProxy.java:482)
    at org.neo4j.elasticsearch.ElasticSearchEventHandler.nodeToJson(ElasticSearchEventHandler.java:188)
    at org.neo4j.elasticsearch.ElasticSearchEventHandler.indexRequests(ElasticSearchEventHandler.java:119)
    at org.neo4j.elasticsearch.ElasticSearchEventHandler.beforeCommit(ElasticSearchEventHandler.java:47)
    at org.neo4j.elasticsearch.ElasticSearchEventHandler.beforeCommit(ElasticSearchEventHandler.java:27)
    at org.neo4j.kernel.TransactionEventHandlers.beforeCommit(TransactionEventHandlers.java:130)
    at org.neo4j.kernel.TransactionEventHandlers.beforeCommit(TransactionEventHandlers.java:49)
    ... 39 more
Caused by: org.neo4j.kernel.api.exceptions.PropertyNotFoundException: NODE[2] has no property with propertyKeyId=31.
    at org.neo4j.kernel.impl.core.NodeProxy.getProperty(NodeProxy.java:475)
    ... 45 more

How can this be achieved if both plugins cannot work together?

2

2 Answers

3
votes

As you are using the UUID module, you can use the GraphAware Neo4j Elasticsearch Integration module, which will take care of using the uuid out of the box.

After a minimal configuration, you will be able to specify which node labels and even which properties have to be indexed.

2
votes

In case you have registered multiple TransactionsEventHandlers be aware that their execution order is not defined. Internally Neo4j uses a CopyOnWriteArraySet, see https://github.com/neo4j/neo4j/blob/3.1/community/kernel/src/main/java/org/neo4j/kernel/internal/TransactionEventHandlers.java#L50

To solve this I suggest to create a DelegatingTransactionEventHandler that has a list of delegates (the uuid tx handler and the elastic tx handler) and executes them in order.