diff --git a/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java b/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java index eab333b094c..5a97798aad3 100644 --- a/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java +++ b/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java @@ -56,7 +56,6 @@ import org.elasticsearch.transport.TransportRequestOptions; import org.elasticsearch.transport.TransportService; import java.io.IOException; -import java.util.Locale; import java.util.Set; /** @@ -184,7 +183,7 @@ public class TransportShardBulkAction extends TransportShardReplicationOperation } // add the response - responses[i] = new BulkItemResponse(item.id(), indexRequest.opType().toString().toLowerCase(Locale.ENGLISH), + responses[i] = new BulkItemResponse(item.id(), indexRequest.opType().lowercase(), new IndexResponse(indexRequest.index(), indexRequest.type(), indexRequest.id(), version)); } catch (Exception e) { // rethrow the failure if we are going to retry on primary and let parent failure to handle it @@ -196,7 +195,7 @@ public class TransportShardBulkAction extends TransportShardReplicationOperation } else { logger.debug("[{}][{}] failed to execute bulk item (index) {}", e, shardRequest.request.index(), shardRequest.shardId, indexRequest); } - responses[i] = new BulkItemResponse(item.id(), indexRequest.opType().toString().toLowerCase(Locale.ENGLISH), + responses[i] = new BulkItemResponse(item.id(), indexRequest.opType().lowercase(), new BulkItemResponse.Failure(indexRequest.index(), indexRequest.type(), indexRequest.id(), ExceptionsHelper.detailedMessage(e))); // nullify the request so it won't execute on the replicas request.items()[i] = null; diff --git a/src/main/java/org/elasticsearch/action/index/IndexRequest.java b/src/main/java/org/elasticsearch/action/index/IndexRequest.java index f258d83b58d..9ae20e9bb58 100644 --- a/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -42,6 +42,7 @@ import org.elasticsearch.index.VersionType; import org.elasticsearch.index.mapper.internal.TimestampFieldMapper; import java.io.IOException; +import java.util.Locale; import java.util.Map; import static org.elasticsearch.action.ValidateActions.addValidationError; @@ -80,10 +81,12 @@ public class IndexRequest extends ShardReplicationOperationRequest */ CREATE((byte) 1); - private byte id; + private final byte id; + private final String lowercase; OpType(byte id) { this.id = id; + this.lowercase = this.toString().toLowerCase(Locale.ENGLISH); } /** @@ -93,6 +96,10 @@ public class IndexRequest extends ShardReplicationOperationRequest return id; } + public String lowercase() { + return this.lowercase; + } + /** * Constructs the operation type from its internal representation. */ @@ -134,20 +141,20 @@ public class IndexRequest extends ShardReplicationOperationRequest /** * Constructs a new index request against the specific index. The {@link #type(String)} - * {@link #source(byte[])} must be set. + * {@link #source(byte[])} must be set. */ public IndexRequest(String index) { this.index = index; } /** - * Constructs a new index request against the specific index and type. The + * Constructs a new index request against the specific index and type. The * {@link #source(byte[])} must be set. */ public IndexRequest(String index, String type) { this.index = index; this.type = type; - } + } /** * Constructs a new index request against the index, type, id and using the source. diff --git a/src/test/java/org/elasticsearch/benchmark/stress/SingleThreadBulkStress.java b/src/test/java/org/elasticsearch/benchmark/stress/SingleThreadBulkStress.java index e415158ad00..c43b42b1b9b 100644 --- a/src/test/java/org/elasticsearch/benchmark/stress/SingleThreadBulkStress.java +++ b/src/test/java/org/elasticsearch/benchmark/stress/SingleThreadBulkStress.java @@ -62,7 +62,8 @@ public class SingleThreadBulkStress { nodes[i] = nodeBuilder().settings(settingsBuilder().put(settings).put("name", "node" + i)).node(); } - Node client = nodeBuilder().settings(settingsBuilder().put(settings).put("name", "client")).client(true).node(); + //Node client = nodeBuilder().settings(settingsBuilder().put(settings).put("name", "client")).client(true).node(); + Node client = nodes[0]; Client client1 = client.client();