From e815f257cc928a04dffbd1b6230396e8d5d3c7cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Deve=CC=80ze?= Date: Sun, 30 Jun 2013 16:24:06 +0200 Subject: [PATCH] Fixes issue that in some cases the doc_as_upsert option is ignored. Closes #3265 --- .../elasticsearch/action/update/UpdateRequest.java | 3 --- .../test/integration/update/UpdateTests.java | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/elasticsearch/action/update/UpdateRequest.java b/src/main/java/org/elasticsearch/action/update/UpdateRequest.java index ac23bbe59bc..d9e0559da75 100644 --- a/src/main/java/org/elasticsearch/action/update/UpdateRequest.java +++ b/src/main/java/org/elasticsearch/action/update/UpdateRequest.java @@ -571,9 +571,6 @@ public class UpdateRequest extends InstanceShardOperationRequest public void docAsUpsert(boolean shouldUpsertDoc) { this.docAsUpsert = shouldUpsertDoc; - if (this.doc != null && this.upsertRequest == null) { - upsert(doc); - } } @Override diff --git a/src/test/java/org/elasticsearch/test/integration/update/UpdateTests.java b/src/test/java/org/elasticsearch/test/integration/update/UpdateTests.java index 758eb2a3a49..cf7ada92757 100644 --- a/src/test/java/org/elasticsearch/test/integration/update/UpdateTests.java +++ b/src/test/java/org/elasticsearch/test/integration/update/UpdateTests.java @@ -183,6 +183,20 @@ public class UpdateTests extends AbstractSharedClusterTest { assertThat(updateResponse.getGetResult().sourceAsMap().get("bar").toString(), equalTo("baz")); } + @Test + public void testNotUpsertDoc() throws Exception { + createIndex(); + ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); + assertThat(clusterHealth.isTimedOut(), equalTo(false)); + assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN)); + + assertThrows(client().prepareUpdate("test", "type1", "1") + .setDoc(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject()) + .setDocAsUpsert(false) + .setFields("_source") + .execute(), DocumentMissingException.class); + } + @Test public void testUpsertFields() throws Exception { createIndex();