Java Code Examples for org.elasticsearch.action.ActionRequest#writeTo()
The following examples show how to use
org.elasticsearch.action.ActionRequest#writeTo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BulkRequest.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeByte(consistencyLevel.id()); out.writeVInt(requests.size()); for (ActionRequest request : requests) { if (request instanceof IndexRequest) { out.writeByte((byte) 0); } else if (request instanceof DeleteRequest) { out.writeByte((byte) 1); } else if (request instanceof UpdateRequest) { out.writeByte((byte) 2); } request.writeTo(out); } out.writeBoolean(refresh); timeout.writeTo(out); }
Example 2
Source File: IngestReplicaShardRequest.java From elasticsearch-helper with Apache License 2.0 | 6 votes |
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeString(index); timeout.writeTo(out); out.writeLong(ingestId); shardId.writeTo(out); out.writeVInt(actionRequests.size()); for (ActionRequest<?> actionRequest : actionRequests) { if (actionRequest == null) { out.writeBoolean(false); continue; } out.writeBoolean(true); if (actionRequest instanceof IndexRequest) { out.writeBoolean(true); } else if (actionRequest instanceof DeleteRequest) { out.writeBoolean(false); } else { throw new ElasticsearchException("action request not supported: " + actionRequest.getClass().getName()); } actionRequest.writeTo(out); } }
Example 3
Source File: IngestLeaderShardRequest.java From elasticsearch-helper with Apache License 2.0 | 6 votes |
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeString(index); timeout.writeTo(out); out.writeByte(requiredConsistency.id()); out.writeLong(ingestId); shardId.writeTo(out); out.writeVInt(actionRequests.size()); for (ActionRequest<?> actionRequest : actionRequests) { if (actionRequest == null) { out.writeBoolean(false); } else { out.writeBoolean(true); if (actionRequest instanceof IndexRequest) { out.writeBoolean(true); } else if (actionRequest instanceof DeleteRequest) { out.writeBoolean(false); } else { throw new ElasticsearchException("action request not supported: " + actionRequest.getClass().getName()); } actionRequest.writeTo(out); } } }
Example 4
Source File: AnomalyResultRequest.java From anomaly-detection with Apache License 2.0 | 5 votes |
public static AnomalyResultRequest fromActionRequest(final ActionRequest actionRequest) { if (actionRequest instanceof AnomalyResultRequest) { return (AnomalyResultRequest) actionRequest; } try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStreamStreamOutput osso = new OutputStreamStreamOutput(baos)) { actionRequest.writeTo(osso); try (StreamInput input = new InputStreamStreamInput(new ByteArrayInputStream(baos.toByteArray()))) { return new AnomalyResultRequest(input); } } catch (IOException e) { throw new IllegalArgumentException("failed to parse ActionRequest into AnomalyResultRequest", e); } }
Example 5
Source File: StopDetectorRequest.java From anomaly-detection with Apache License 2.0 | 5 votes |
public static StopDetectorRequest fromActionRequest(final ActionRequest actionRequest) { if (actionRequest instanceof StopDetectorRequest) { return (StopDetectorRequest) actionRequest; } try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStreamStreamOutput osso = new OutputStreamStreamOutput(baos)) { actionRequest.writeTo(osso); try (StreamInput input = new InputStreamStreamInput(new ByteArrayInputStream(baos.toByteArray()))) { return new StopDetectorRequest(input); } } catch (IOException e) { throw new IllegalArgumentException("failed to parse ActionRequest into StopDetectorRequest", e); } }
Example 6
Source File: IngestRequest.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@Override public void writeTo(StreamOutput out) throws IOException { timeout.writeTo(out); out.writeLong(ingestId); out.writeVInt(requests.size()); for (ActionRequest<?> request : requests) { if (request instanceof IndexRequest) { out.writeByte((byte) 0); } else if (request instanceof DeleteRequest) { out.writeByte((byte) 1); } request.writeTo(out); } }
Example 7
Source File: IngestLeaderShardResponse.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeLong(tookInMillis); out.writeLong(ingestId); if (shardId == null) { out.writeBoolean(false); } else { out.writeBoolean(true); shardId.writeTo(out); } out.writeVInt(successCount); out.writeVInt(quorumShards); out.writeVInt(actionRequests.size()); for (ActionRequest<?> actionRequest : actionRequests) { if (actionRequest == null) { out.writeBoolean(false); } else { out.writeBoolean(true); if (actionRequest instanceof IndexRequest) { out.writeBoolean(true); } else if (actionRequest instanceof DeleteRequest) { out.writeBoolean(false); } else { throw new ElasticsearchException("action request not supported: " + actionRequest.getClass().getName()); } actionRequest.writeTo(out); } } out.writeVInt(failures.size()); for (IngestActionFailure f : failures) { f.writeTo(out); } }
Example 8
Source File: ElasticSearchHelper.java From camunda-bpm-elasticsearch with Apache License 2.0 | 5 votes |
public static String convertRequestToJson(ActionRequest request) throws IOException { BytesStreamOutput bytesStreamOutput = new BytesStreamOutput(); request.writeTo(bytesStreamOutput); XContentBuilder builder = XContentFactory.jsonBuilder(bytesStreamOutput); builder.prettyPrint(); // builder.startObject(); // builder.endObject(); BytesArray bytesArray = builder.bytes().toBytesArray(); return new String(bytesArray.array(), bytesArray.arrayOffset(), bytesArray.length()); }