rename doc to upsert in update API
a better descriptive name for it, and won't clash with future features on the update api
This commit is contained in:
parent
e4b11e0b15
commit
0b4fe4add3
|
@ -165,11 +165,11 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio
|
|||
|
||||
// no doc, what to do, what to do...
|
||||
if (!getResult.exists()) {
|
||||
if (request.indexRequest() == null) {
|
||||
if (request.upsertRequest() == null) {
|
||||
listener.onFailure(new DocumentMissingException(new ShardId(request.index(), request.shardId()), request.type(), request.id()));
|
||||
return;
|
||||
}
|
||||
IndexRequest indexRequest = request.indexRequest();
|
||||
IndexRequest indexRequest = request.upsertRequest();
|
||||
indexRequest.index(request.index()).type(request.type()).id(request.id())
|
||||
// it has to be a "create!"
|
||||
.create(true)
|
||||
|
|
|
@ -63,7 +63,7 @@ public class UpdateRequest extends InstanceShardOperationRequest {
|
|||
private ReplicationType replicationType = ReplicationType.DEFAULT;
|
||||
private WriteConsistencyLevel consistencyLevel = WriteConsistencyLevel.DEFAULT;
|
||||
|
||||
private IndexRequest indexRequest;
|
||||
private IndexRequest upsertRequest;
|
||||
|
||||
UpdateRequest() {
|
||||
|
||||
|
@ -339,68 +339,68 @@ public class UpdateRequest extends InstanceShardOperationRequest {
|
|||
* Sets the index request to be used if the document does not exists. Otherwise, a {@link org.elasticsearch.index.engine.DocumentMissingException}
|
||||
* is thrown.
|
||||
*/
|
||||
public UpdateRequest doc(IndexRequest indexRequest) {
|
||||
this.indexRequest = indexRequest;
|
||||
public UpdateRequest upsert(IndexRequest upsertRequest) {
|
||||
this.upsertRequest = upsertRequest;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the doc source of the update request to be used when the document does not exists.
|
||||
*/
|
||||
public UpdateRequest doc(XContentBuilder source) {
|
||||
safeIndexRequest().source(source);
|
||||
public UpdateRequest upsert(XContentBuilder source) {
|
||||
safeUpsertRequest().source(source);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the doc source of the update request to be used when the document does not exists.
|
||||
*/
|
||||
public UpdateRequest doc(Map source) {
|
||||
safeIndexRequest().source(source);
|
||||
public UpdateRequest upsert(Map source) {
|
||||
safeUpsertRequest().source(source);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the doc source of the update request to be used when the document does not exists.
|
||||
*/
|
||||
public UpdateRequest doc(Map source, XContentType contentType) {
|
||||
safeIndexRequest().source(source, contentType);
|
||||
public UpdateRequest upsert(Map source, XContentType contentType) {
|
||||
safeUpsertRequest().source(source, contentType);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the doc source of the update request to be used when the document does not exists.
|
||||
*/
|
||||
public UpdateRequest doc(String source) {
|
||||
safeIndexRequest().source(source);
|
||||
public UpdateRequest upsert(String source) {
|
||||
safeUpsertRequest().source(source);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the doc source of the update request to be used when the document does not exists.
|
||||
*/
|
||||
public UpdateRequest doc(byte[] source) {
|
||||
safeIndexRequest().source(source);
|
||||
public UpdateRequest upsert(byte[] source) {
|
||||
safeUpsertRequest().source(source);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the doc source of the update request to be used when the document does not exists.
|
||||
*/
|
||||
public UpdateRequest doc(byte[] source, int offset, int length) {
|
||||
safeIndexRequest().source(source, offset, length);
|
||||
public UpdateRequest upsert(byte[] source, int offset, int length) {
|
||||
safeUpsertRequest().source(source, offset, length);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IndexRequest indexRequest() {
|
||||
return this.indexRequest;
|
||||
public IndexRequest upsertRequest() {
|
||||
return this.upsertRequest;
|
||||
}
|
||||
|
||||
private IndexRequest safeIndexRequest() {
|
||||
if (indexRequest == null) {
|
||||
indexRequest = new IndexRequest();
|
||||
private IndexRequest safeUpsertRequest() {
|
||||
if (upsertRequest == null) {
|
||||
upsertRequest = new IndexRequest();
|
||||
}
|
||||
return indexRequest;
|
||||
return upsertRequest;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -431,8 +431,8 @@ public class UpdateRequest extends InstanceShardOperationRequest {
|
|||
}
|
||||
}
|
||||
if (in.readBoolean()) {
|
||||
indexRequest = new IndexRequest();
|
||||
indexRequest.readFrom(in);
|
||||
upsertRequest = new IndexRequest();
|
||||
upsertRequest.readFrom(in);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -473,15 +473,15 @@ public class UpdateRequest extends InstanceShardOperationRequest {
|
|||
out.writeUTF(field);
|
||||
}
|
||||
}
|
||||
if (indexRequest == null) {
|
||||
if (upsertRequest == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
// make sure the basics are set
|
||||
indexRequest.index(index);
|
||||
indexRequest.type(type);
|
||||
indexRequest.id(id);
|
||||
indexRequest.writeTo(out);
|
||||
upsertRequest.index(index);
|
||||
upsertRequest.type(type);
|
||||
upsertRequest.id(id);
|
||||
upsertRequest.writeTo(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,56 +187,56 @@ public class UpdateRequestBuilder extends BaseRequestBuilder<UpdateRequest, Upda
|
|||
* Sets the index request to be used if the document does not exists. Otherwise, a {@link org.elasticsearch.index.engine.DocumentMissingException}
|
||||
* is thrown.
|
||||
*/
|
||||
public UpdateRequestBuilder setDoc(IndexRequest indexRequest) {
|
||||
request.doc(indexRequest);
|
||||
public UpdateRequestBuilder setUpsert(IndexRequest indexRequest) {
|
||||
request.upsert(indexRequest);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the doc source of the update request to be used when the document does not exists.
|
||||
*/
|
||||
public UpdateRequestBuilder setDoc(XContentBuilder source) {
|
||||
request.doc(source);
|
||||
public UpdateRequestBuilder setUpsert(XContentBuilder source) {
|
||||
request.upsert(source);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the doc source of the update request to be used when the document does not exists.
|
||||
*/
|
||||
public UpdateRequestBuilder setDoc(Map source) {
|
||||
request.doc(source);
|
||||
public UpdateRequestBuilder setUpsert(Map source) {
|
||||
request.upsert(source);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the doc source of the update request to be used when the document does not exists.
|
||||
*/
|
||||
public UpdateRequestBuilder setDoc(Map source, XContentType contentType) {
|
||||
request.doc(source, contentType);
|
||||
public UpdateRequestBuilder setUpsert(Map source, XContentType contentType) {
|
||||
request.upsert(source, contentType);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the doc source of the update request to be used when the document does not exists.
|
||||
*/
|
||||
public UpdateRequestBuilder setDoc(String source) {
|
||||
request.doc(source);
|
||||
public UpdateRequestBuilder setUpsert(String source) {
|
||||
request.upsert(source);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the doc source of the update request to be used when the document does not exists.
|
||||
*/
|
||||
public UpdateRequestBuilder setDoc(byte[] source) {
|
||||
request.doc(source);
|
||||
public UpdateRequestBuilder setUpsert(byte[] source) {
|
||||
request.upsert(source);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the doc source of the update request to be used when the document does not exists.
|
||||
*/
|
||||
public UpdateRequestBuilder setDoc(byte[] source, int offset, int length) {
|
||||
request.doc(source, offset, length);
|
||||
public UpdateRequestBuilder setUpsert(byte[] source, int offset, int length) {
|
||||
request.upsert(source, offset, length);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -104,9 +104,9 @@ public class RestUpdateAction extends BaseRestHandler {
|
|||
if (content.containsKey("params")) {
|
||||
updateRequest.scriptParams((Map<String, Object>) content.get("params"));
|
||||
}
|
||||
if (content.containsKey("doc")) {
|
||||
if (content.containsKey("upsert")) {
|
||||
IndexRequest indexRequest = new IndexRequest();
|
||||
indexRequest.source((Map) content.get("doc"), xContentType);
|
||||
indexRequest.source((Map) content.get("upsert"), xContentType);
|
||||
indexRequest.routing(request.param("routing"));
|
||||
indexRequest.parent(request.param("parent")); // order is important, set it after routing, so it will set the routing
|
||||
indexRequest.timestamp(request.param("timestamp"));
|
||||
|
@ -115,7 +115,7 @@ public class RestUpdateAction extends BaseRestHandler {
|
|||
}
|
||||
indexRequest.version(RestActions.parseVersion(request));
|
||||
indexRequest.versionType(VersionType.fromString(request.param("version_type"), indexRequest.versionType()));
|
||||
updateRequest.doc(indexRequest);
|
||||
updateRequest.upsert(indexRequest);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
|
|
|
@ -92,7 +92,7 @@ public class UpdateTests extends AbstractNodesTests {
|
|||
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
|
||||
|
||||
client.prepareUpdate("test", "type1", "1")
|
||||
.setDoc(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject())
|
||||
.setUpsert(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject())
|
||||
.setScript("ctx._source.field += 1")
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -102,7 +102,7 @@ public class UpdateTests extends AbstractNodesTests {
|
|||
}
|
||||
|
||||
client.prepareUpdate("test", "type1", "1")
|
||||
.setDoc(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject())
|
||||
.setUpsert(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject())
|
||||
.setScript("ctx._source.field += 1")
|
||||
.execute().actionGet();
|
||||
|
||||
|
|
Loading…
Reference in New Issue