diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java index 241ec97db9d..064657cd1e0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java @@ -634,7 +634,8 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { updatedVersion = currentVersion < 0 ? 1 : currentVersion + 1; } else { // External if (currentVersion == -1) { - throw new VersionConflictEngineException(shardId, delete.type(), delete.id(), -1, delete.version()); + // its an external version, that's fine, we allow it to be set + //throw new VersionConflictEngineException(shardId, delete.type(), delete.id(), -1, delete.version()); } else if (currentVersion >= delete.version()) { throw new VersionConflictEngineException(shardId, delete.type(), delete.id(), currentVersion, delete.version()); } diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/versioning/SimpleVersioningTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/versioning/SimpleVersioningTests.java index de9f1ab00f9..6ee70fd43c7 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/versioning/SimpleVersioningTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/versioning/SimpleVersioningTests.java @@ -61,6 +61,24 @@ public class SimpleVersioningTests extends AbstractNodesTests { closeAllNodes(); } + @Test public void testExternalVersioningInitialDelete() throws Exception { + client.admin().indices().prepareDelete().execute().actionGet(); + + client.admin().indices().prepareCreate("test").execute().actionGet(); + client.admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet(); + + DeleteResponse deleteResponse = client2.prepareDelete("test", "type", "1").setVersion(17).setVersionType(VersionType.EXTERNAL).execute().actionGet(); + assertThat(deleteResponse.notFound(), equalTo(true)); + + try { + client.prepareIndex("test", "type", "1").setSource("field1", "value1_1").setVersion(13).setVersionType(VersionType.EXTERNAL).execute().actionGet(); + } catch (ElasticSearchException e) { + assertThat(e.unwrapCause(), instanceOf(VersionConflictEngineException.class)); + } + + client.prepareIndex("test", "type", "1").setSource("field1", "value1_1").setVersion(18).setVersionType(VersionType.EXTERNAL).execute().actionGet(); + } + @Test public void testExternalVersioning() throws Exception { try { client.admin().indices().prepareDelete("test").execute().actionGet();