本文整理汇总了Java中org.elasticsearch.action.DocWriteRequest.OpType方法的典型用法代码示例。如果您正苦于以下问题:Java DocWriteRequest.OpType方法的具体用法?Java DocWriteRequest.OpType怎么用?Java DocWriteRequest.OpType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.DocWriteRequest
的用法示例。
在下文中一共展示了DocWriteRequest.OpType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testToAndFromXContent
import org.elasticsearch.action.DocWriteRequest; //导入方法依赖的package包/类
public void testToAndFromXContent() throws IOException {
final XContentType xContentType = randomFrom(XContentType.values());
for (DocWriteRequest.OpType opType : DocWriteRequest.OpType.values()) {
int bulkItemId = randomIntBetween(0, 100);
boolean humanReadable = randomBoolean();
Tuple<? extends DocWriteResponse, ? extends DocWriteResponse> randomDocWriteResponses = null;
if (opType == DocWriteRequest.OpType.INDEX || opType == DocWriteRequest.OpType.CREATE) {
randomDocWriteResponses = IndexResponseTests.randomIndexResponse();
} else if (opType == DocWriteRequest.OpType.DELETE) {
randomDocWriteResponses = DeleteResponseTests.randomDeleteResponse();
} else if (opType == DocWriteRequest.OpType.UPDATE) {
randomDocWriteResponses = UpdateResponseTests.randomUpdateResponse(xContentType);
} else {
fail("Test does not support opType [" + opType + "]");
}
BulkItemResponse bulkItemResponse = new BulkItemResponse(bulkItemId, opType, randomDocWriteResponses.v1());
BulkItemResponse expectedBulkItemResponse = new BulkItemResponse(bulkItemId, opType, randomDocWriteResponses.v2());
BytesReference originalBytes = toXContent(bulkItemResponse, xContentType, humanReadable);
// Shuffle the XContent fields
if (randomBoolean()) {
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
originalBytes = shuffleXContent(parser, randomBoolean()).bytes();
}
}
BulkItemResponse parsedBulkItemResponse;
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
parsedBulkItemResponse = BulkItemResponse.fromXContent(parser, bulkItemId);
assertNull(parser.nextToken());
}
assertBulkItemResponse(expectedBulkItemResponse, parsedBulkItemResponse);
}
}
示例2: testFailureToAndFromXContent
import org.elasticsearch.action.DocWriteRequest; //导入方法依赖的package包/类
public void testFailureToAndFromXContent() throws IOException {
final XContentType xContentType = randomFrom(XContentType.values());
int itemId = randomIntBetween(0, 100);
String index = randomAsciiOfLength(5);
String type = randomAsciiOfLength(5);
String id = randomAsciiOfLength(5);
DocWriteRequest.OpType opType = randomFrom(DocWriteRequest.OpType.values());
final Tuple<Throwable, ElasticsearchException> exceptions = randomExceptions();
Exception bulkItemCause = (Exception) exceptions.v1();
Failure bulkItemFailure = new Failure(index, type, id, bulkItemCause);
BulkItemResponse bulkItemResponse = new BulkItemResponse(itemId, opType, bulkItemFailure);
Failure expectedBulkItemFailure = new Failure(index, type, id, exceptions.v2(), ExceptionsHelper.status(bulkItemCause));
BulkItemResponse expectedBulkItemResponse = new BulkItemResponse(itemId, opType, expectedBulkItemFailure);
BytesReference originalBytes = toXContent(bulkItemResponse, xContentType, randomBoolean());
// Shuffle the XContent fields
if (randomBoolean()) {
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
originalBytes = shuffleXContent(parser, randomBoolean()).bytes();
}
}
BulkItemResponse parsedBulkItemResponse;
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
parsedBulkItemResponse = BulkItemResponse.fromXContent(parser, itemId);
assertNull(parser.nextToken());
}
assertBulkItemResponse(expectedBulkItemResponse, parsedBulkItemResponse);
}
示例3: setOpType
import org.elasticsearch.action.DocWriteRequest; //导入方法依赖的package包/类
/**
* Sets the type of operation to perform.
*/
public IndexRequestBuilder setOpType(DocWriteRequest.OpType opType) {
request.opType(opType);
return this;
}
示例4: updateReplicaRequest
import org.elasticsearch.action.DocWriteRequest; //导入方法依赖的package包/类
static Translog.Location updateReplicaRequest(BulkItemResultHolder bulkItemResult,
final DocWriteRequest.OpType opType,
final Translog.Location originalLocation,
BulkShardRequest request) {
final Engine.Result operationResult = bulkItemResult.operationResult;
final DocWriteResponse response = bulkItemResult.response;
final BulkItemRequest replicaRequest = bulkItemResult.replicaRequest;
if (operationResult == null) { // in case of noop update operation
assert response.getResult() == DocWriteResponse.Result.NOOP : "only noop updates can have a null operation";
replicaRequest.setPrimaryResponse(new BulkItemResponse(replicaRequest.id(), opType, response));
return originalLocation;
} else if (operationResult.hasFailure() == false) {
BulkItemResponse primaryResponse = new BulkItemResponse(replicaRequest.id(), opType, response);
replicaRequest.setPrimaryResponse(primaryResponse);
// set a blank ShardInfo so we can safely send it to the replicas. We won't use it in the real response though.
primaryResponse.getResponse().setShardInfo(new ShardInfo());
// The operation was successful, advance the translog
return locationToSync(originalLocation, operationResult.getTranslogLocation());
} else {
DocWriteRequest docWriteRequest = replicaRequest.request();
Exception failure = operationResult.getFailure();
if (isConflictException(failure)) {
logger.trace((Supplier<?>) () -> new ParameterizedMessage("{} failed to execute bulk item ({}) {}",
request.shardId(), docWriteRequest.opType().getLowercase(), request), failure);
} else {
logger.debug((Supplier<?>) () -> new ParameterizedMessage("{} failed to execute bulk item ({}) {}",
request.shardId(), docWriteRequest.opType().getLowercase(), request), failure);
}
// if it's a conflict failure, and we already executed the request on a primary (and we execute it
// again, due to primary relocation and only processing up to N bulk items when the shard gets closed)
// then just use the response we got from the failed execution
if (replicaRequest.getPrimaryResponse() == null || isConflictException(failure) == false) {
replicaRequest.setPrimaryResponse(
new BulkItemResponse(replicaRequest.id(), docWriteRequest.opType(),
// Make sure to use request.indox() here, if you
// use docWriteRequest.index() it will use the
// concrete index instead of an alias if used!
new BulkItemResponse.Failure(request.index(), docWriteRequest.type(), docWriteRequest.id(), failure)));
}
return originalLocation;
}
}
示例5: testBulkResponseSetsLotsOfStatus
import org.elasticsearch.action.DocWriteRequest; //导入方法依赖的package包/类
public void testBulkResponseSetsLotsOfStatus() {
testRequest.setAbortOnVersionConflict(false);
int maxBatches = randomIntBetween(0, 100);
long versionConflicts = 0;
long created = 0;
long updated = 0;
long deleted = 0;
for (int batches = 0; batches < maxBatches; batches++) {
BulkItemResponse[] responses = new BulkItemResponse[randomIntBetween(0, 100)];
for (int i = 0; i < responses.length; i++) {
ShardId shardId = new ShardId(new Index("name", "uid"), 0);
if (rarely()) {
versionConflicts++;
responses[i] = new BulkItemResponse(i, randomFrom(DocWriteRequest.OpType.values()),
new Failure(shardId.getIndexName(), "type", "id" + i,
new VersionConflictEngineException(shardId, "type", "id", "test")));
continue;
}
boolean createdResponse;
DocWriteRequest.OpType opType;
switch (randomIntBetween(0, 2)) {
case 0:
createdResponse = true;
opType = DocWriteRequest.OpType.CREATE;
created++;
break;
case 1:
createdResponse = false;
opType = randomFrom(DocWriteRequest.OpType.INDEX, DocWriteRequest.OpType.UPDATE);
updated++;
break;
case 2:
createdResponse = false;
opType = DocWriteRequest.OpType.DELETE;
deleted++;
break;
default:
throw new RuntimeException("Bad scenario");
}
responses[i] = new BulkItemResponse(
i,
opType,
new IndexResponse(shardId, "type", "id" + i, randomInt(20), randomInt(), createdResponse));
}
new DummyAsyncBulkByScrollAction().onBulkResponse(timeValueNanos(System.nanoTime()), new BulkResponse(responses, 0));
assertEquals(versionConflicts, testTask.getStatus().getVersionConflicts());
assertEquals(updated, testTask.getStatus().getUpdated());
assertEquals(created, testTask.getStatus().getCreated());
assertEquals(deleted, testTask.getStatus().getDeleted());
assertEquals(versionConflicts, testTask.getStatus().getVersionConflicts());
}
}
示例6: testToAndFromXContent
import org.elasticsearch.action.DocWriteRequest; //导入方法依赖的package包/类
public void testToAndFromXContent() throws IOException {
XContentType xContentType = randomFrom(XContentType.values());
boolean humanReadable = randomBoolean();
long took = randomFrom(randomNonNegativeLong(), -1L);
long ingestTook = randomFrom(randomNonNegativeLong(), NO_INGEST_TOOK);
int nbBulkItems = randomIntBetween(1, 10);
BulkItemResponse[] bulkItems = new BulkItemResponse[nbBulkItems];
BulkItemResponse[] expectedBulkItems = new BulkItemResponse[nbBulkItems];
for (int i = 0; i < nbBulkItems; i++) {
DocWriteRequest.OpType opType = randomFrom(DocWriteRequest.OpType.values());
if (frequently()) {
Tuple<? extends DocWriteResponse, ? extends DocWriteResponse> randomDocWriteResponses = null;
if (opType == DocWriteRequest.OpType.INDEX || opType == DocWriteRequest.OpType.CREATE) {
randomDocWriteResponses = IndexResponseTests.randomIndexResponse();
} else if (opType == DocWriteRequest.OpType.DELETE) {
randomDocWriteResponses = DeleteResponseTests.randomDeleteResponse();
} else if (opType == DocWriteRequest.OpType.UPDATE) {
randomDocWriteResponses = UpdateResponseTests.randomUpdateResponse(xContentType);
} else {
fail("Test does not support opType [" + opType + "]");
}
bulkItems[i] = new BulkItemResponse(i, opType, randomDocWriteResponses.v1());
expectedBulkItems[i] = new BulkItemResponse(i, opType, randomDocWriteResponses.v2());
} else {
String index = randomAsciiOfLength(5);
String type = randomAsciiOfLength(5);
String id = randomAsciiOfLength(5);
Tuple<Throwable, ElasticsearchException> failures = randomExceptions();
Exception bulkItemCause = (Exception) failures.v1();
bulkItems[i] = new BulkItemResponse(i, opType,
new BulkItemResponse.Failure(index, type, id, bulkItemCause));
expectedBulkItems[i] = new BulkItemResponse(i, opType,
new BulkItemResponse.Failure(index, type, id, failures.v2(), ExceptionsHelper.status(bulkItemCause)));
}
}
BulkResponse bulkResponse = new BulkResponse(bulkItems, took, ingestTook);
BytesReference originalBytes = toXContent(bulkResponse, xContentType, humanReadable);
if (randomBoolean()) {
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
originalBytes = shuffleXContent(parser, randomBoolean()).bytes();
}
}
BulkResponse parsedBulkResponse;
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
parsedBulkResponse = BulkResponse.fromXContent(parser);
assertNull(parser.nextToken());
}
assertEquals(took, parsedBulkResponse.getTookInMillis());
assertEquals(ingestTook, parsedBulkResponse.getIngestTookInMillis());
assertEquals(expectedBulkItems.length, parsedBulkResponse.getItems().length);
for (int i = 0; i < expectedBulkItems.length; i++) {
assertBulkItemResponse(expectedBulkItems[i], parsedBulkResponse.getItems()[i]);
}
BytesReference finalBytes = toXContent(parsedBulkResponse, xContentType, humanReadable);
BytesReference expectedFinalBytes = toXContent(parsedBulkResponse, xContentType, humanReadable);
assertToXContentEquivalent(expectedFinalBytes, finalBytes, xContentType);
}