Skip to content

Commit

Permalink
Remove some duplication from BulkRequestParser (#109302)
Browse files Browse the repository at this point in the history
No need to duplicate most of the index-request building 3x.
  • Loading branch information
original-brownbear authored Jun 19, 2024
1 parent 5ef4e81 commit 227034e
Showing 1 changed file with 18 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,58 +341,25 @@ public void parse(

// we use internalAdd so we don't fork here, this allows us not to copy over the big byte array to small chunks
// of index request.
if ("index".equals(action)) {
if (opType == null) {
indexRequestConsumer.accept(
new IndexRequest(index).id(id)
.routing(routing)
.version(version)
.versionType(versionType)
.setPipeline(pipeline)
.setIfSeqNo(ifSeqNo)
.setIfPrimaryTerm(ifPrimaryTerm)
.source(sliceTrimmingCarriageReturn(data, from, nextMarker, xContentType), xContentType)
.setDynamicTemplates(dynamicTemplates)
.setRequireAlias(requireAlias)
.setRequireDataStream(requireDataStream)
.setListExecutedPipelines(listExecutedPipelines),
type
);
} else {
indexRequestConsumer.accept(
new IndexRequest(index).id(id)
.routing(routing)
.version(version)
.versionType(versionType)
.create("create".equals(opType))
.setPipeline(pipeline)
.setIfSeqNo(ifSeqNo)
.setIfPrimaryTerm(ifPrimaryTerm)
.source(sliceTrimmingCarriageReturn(data, from, nextMarker, xContentType), xContentType)
.setDynamicTemplates(dynamicTemplates)
.setRequireAlias(requireAlias)
.setRequireDataStream(requireDataStream)
.setListExecutedPipelines(listExecutedPipelines),
type
);
if ("index".equals(action) || "create".equals(action)) {
var indexRequest = new IndexRequest(index).id(id)
.routing(routing)
.version(version)
.versionType(versionType)
.setPipeline(pipeline)
.setIfSeqNo(ifSeqNo)
.setIfPrimaryTerm(ifPrimaryTerm)
.source(sliceTrimmingCarriageReturn(data, from, nextMarker, xContentType), xContentType)
.setDynamicTemplates(dynamicTemplates)
.setRequireAlias(requireAlias)
.setRequireDataStream(requireDataStream)
.setListExecutedPipelines(listExecutedPipelines);
if ("create".equals(action)) {
indexRequest = indexRequest.create(true);
} else if (opType != null) {
indexRequest = indexRequest.create("create".equals(opType));
}
} else if ("create".equals(action)) {
indexRequestConsumer.accept(
new IndexRequest(index).id(id)
.routing(routing)
.version(version)
.versionType(versionType)
.create(true)
.setPipeline(pipeline)
.setIfSeqNo(ifSeqNo)
.setIfPrimaryTerm(ifPrimaryTerm)
.source(sliceTrimmingCarriageReturn(data, from, nextMarker, xContentType), xContentType)
.setDynamicTemplates(dynamicTemplates)
.setRequireAlias(requireAlias)
.setRequireDataStream(requireDataStream)
.setListExecutedPipelines(listExecutedPipelines),
type
);
indexRequestConsumer.accept(indexRequest, type);
} else if ("update".equals(action)) {
if (version != Versions.MATCH_ANY || versionType != VersionType.INTERNAL) {
throw new IllegalArgumentException(
Expand Down

0 comments on commit 227034e

Please sign in to comment.