neo4j-contrib / neo4j-elasticsearch

Neo4j ElasticSearch Integration
Apache License 2.0
210 stars 79 forks source link

Transaction failure when new node lacks a property in the index spec #12

Closed smackesey closed 8 years ago

smackesey commented 9 years ago

My index spec reads elasticsearch.index_spec=stmpd:stmpd(notes). Some of my stmpd-labeled nodes have a notes field and some do not. When I use the plugin, if I try to create a new node without the notes field, I get a Neo4j error:

Transaction was marked as successful, but unable to commit transaction so rolled back.

Is this intended behavior? If it is, is there some way that I can configure the plugin to allow the creation of new Neo4j nodes with an optional indexed property?

jazzido commented 9 years ago

Hi @smackesey,

The behavior for that case is undefined, but I'm inclined to think that if a node does not contain a property specified in the index_spec, the plugin shouldn't throw an error.

I'm unfortunately unable to commit a fix for this, but you might want to take a look at my fork of neo4-elasticsearch, which might not show this bug. In any case, a patch and testcase would be more than welcome; the relevant code is the beforeCommit method in ElasticSearchEventHandler.java

jexp commented 9 years ago

I think it should just silently ignore that property then. Or probably index it with a default which we could add to the config.

e.g.

elasticsearch.index_spec=people:Person(first_name:"n.A",last_name:"None"), places:Place(name:"Nowhere")
smackesey commented 9 years ago

Just created a PR, don't know whether it's acceptable but happy to incorporate feedback. Also, @jazzido I tried building your fork but it failed on my machine (I'm on OS X with Java 8 Update 31). I'm posting what I think is the relevant part of the backtrace:

Running org.neo4j.elasticsearch.ElasticSearchImportAppTest Welcome to the Neo4j Shell! Enter 'help' for a list of commands

Connected to ES cluster: http://localhost:9200 Welcome to the Neo4j Shell! Enter 'help' for a list of commands

Connected to ES cluster: http://localhost:9200 Indexing MyLabel to my_index Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 3.901 sec <<< FAILURE! testBadSyntaxShouldThrow(org.neo4j.elasticsearch.ElasticSearchImportAppTest) Time elapsed: 0.251 sec <<< FAILURE! java.lang.AssertionError: Expected exception: java.lang.Exception at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:32) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)