Fixes issue that in some cases the doc_as_upsert option is ignored.

Closes #3265
This commit is contained in:
Benjamin Devèze 2013-06-30 16:24:06 +02:00 committed by Martijn van Groningen
parent 40cd549c37
commit e815f257cc
2 changed files with 14 additions and 3 deletions

View File

@ -571,9 +571,6 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
public void docAsUpsert(boolean shouldUpsertDoc) {
this.docAsUpsert = shouldUpsertDoc;
if (this.doc != null && this.upsertRequest == null) {
upsert(doc);
}
}
@Override

View File

@ -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();