parent
1ded45b0a2
commit
96ba0b13e0
|
@ -20,6 +20,7 @@
|
||||||
package org.elasticsearch.script.mustache;
|
package org.elasticsearch.script.mustache;
|
||||||
|
|
||||||
import org.elasticsearch.action.Action;
|
import org.elasticsearch.action.Action;
|
||||||
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
|
|
||||||
public class MultiSearchTemplateAction extends Action<MultiSearchTemplateResponse> {
|
public class MultiSearchTemplateAction extends Action<MultiSearchTemplateResponse> {
|
||||||
|
|
||||||
|
@ -32,6 +33,11 @@ public class MultiSearchTemplateAction extends Action<MultiSearchTemplateRespons
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultiSearchTemplateResponse newResponse() {
|
public MultiSearchTemplateResponse newResponse() {
|
||||||
return new MultiSearchTemplateResponse();
|
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Writeable.Reader<MultiSearchTemplateResponse> getResponseReader() {
|
||||||
|
return MultiSearchTemplateResponse::new;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.io.stream.Streamable;
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||||
|
@ -43,11 +43,19 @@ public class MultiSearchTemplateResponse extends ActionResponse implements Itera
|
||||||
/**
|
/**
|
||||||
* A search template response item, holding the actual search template response, or an error message if it failed.
|
* A search template response item, holding the actual search template response, or an error message if it failed.
|
||||||
*/
|
*/
|
||||||
public static class Item implements Streamable {
|
public static class Item implements Writeable {
|
||||||
private SearchTemplateResponse response;
|
private final SearchTemplateResponse response;
|
||||||
private Exception exception;
|
private final Exception exception;
|
||||||
|
|
||||||
Item() {
|
private Item(StreamInput in) throws IOException {
|
||||||
|
if (in.readBoolean()) {
|
||||||
|
this.response = new SearchTemplateResponse();
|
||||||
|
response.readFrom(in);
|
||||||
|
this.exception = null;
|
||||||
|
} else {
|
||||||
|
exception = in.readException();
|
||||||
|
this.response = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item(SearchTemplateResponse response, Exception exception) {
|
public Item(SearchTemplateResponse response, Exception exception) {
|
||||||
|
@ -78,22 +86,6 @@ public class MultiSearchTemplateResponse extends ActionResponse implements Itera
|
||||||
return this.response;
|
return this.response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Item readItem(StreamInput in) throws IOException {
|
|
||||||
Item item = new Item();
|
|
||||||
item.readFrom(in);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
|
||||||
if (in.readBoolean()) {
|
|
||||||
this.response = new SearchTemplateResponse();
|
|
||||||
response.readFrom(in);
|
|
||||||
} else {
|
|
||||||
exception = in.readException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
|
@ -113,17 +105,25 @@ public class MultiSearchTemplateResponse extends ActionResponse implements Itera
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Item [response=" + response + ", exception=" + exception + "]";
|
return "Item [response=" + response + ", exception=" + exception + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Item[] items;
|
private final Item[] items;
|
||||||
private long tookInMillis;
|
private final long tookInMillis;
|
||||||
|
|
||||||
MultiSearchTemplateResponse() {
|
MultiSearchTemplateResponse(StreamInput in) throws IOException {
|
||||||
|
super(in);
|
||||||
|
items = new Item[in.readVInt()];
|
||||||
|
for (int i = 0; i < items.length; i++) {
|
||||||
|
items[i] = new Item(in);
|
||||||
|
}
|
||||||
|
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
|
||||||
|
tookInMillis = in.readVLong();
|
||||||
|
} else {
|
||||||
|
tookInMillis = -1L;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiSearchTemplateResponse(Item[] items, long tookInMillis) {
|
MultiSearchTemplateResponse(Item[] items, long tookInMillis) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
this.tookInMillis = tookInMillis;
|
this.tookInMillis = tookInMillis;
|
||||||
}
|
}
|
||||||
|
@ -149,14 +149,7 @@ public class MultiSearchTemplateResponse extends ActionResponse implements Itera
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
super.readFrom(in);
|
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
|
||||||
items = new Item[in.readVInt()];
|
|
||||||
for (int i = 0; i < items.length; i++) {
|
|
||||||
items[i] = Item.readItem(in);
|
|
||||||
}
|
|
||||||
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
|
|
||||||
tookInMillis = in.readVLong();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.elasticsearch.action.search;
|
package org.elasticsearch.action.search;
|
||||||
|
|
||||||
import org.elasticsearch.action.Action;
|
import org.elasticsearch.action.Action;
|
||||||
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
|
|
||||||
public class MultiSearchAction extends Action<MultiSearchResponse> {
|
public class MultiSearchAction extends Action<MultiSearchResponse> {
|
||||||
|
|
||||||
|
@ -32,6 +33,11 @@ public class MultiSearchAction extends Action<MultiSearchResponse> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultiSearchResponse newResponse() {
|
public MultiSearchResponse newResponse() {
|
||||||
return new MultiSearchResponse();
|
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Writeable.Reader<MultiSearchResponse> getResponseReader() {
|
||||||
|
return MultiSearchResponse::new;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.io.stream.Streamable;
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||||
|
@ -60,19 +60,37 @@ public class MultiSearchResponse extends ActionResponse implements Iterable<Mult
|
||||||
/**
|
/**
|
||||||
* A search response item, holding the actual search response, or an error message if it failed.
|
* A search response item, holding the actual search response, or an error message if it failed.
|
||||||
*/
|
*/
|
||||||
public static class Item implements Streamable {
|
public static class Item implements Writeable {
|
||||||
private SearchResponse response;
|
private final SearchResponse response;
|
||||||
private Exception exception;
|
private final Exception exception;
|
||||||
|
|
||||||
Item() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Item(SearchResponse response, Exception exception) {
|
public Item(SearchResponse response, Exception exception) {
|
||||||
this.response = response;
|
this.response = response;
|
||||||
this.exception = exception;
|
this.exception = exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Item(StreamInput in) throws IOException{
|
||||||
|
if (in.readBoolean()) {
|
||||||
|
this.response = new SearchResponse();
|
||||||
|
this.response.readFrom(in);
|
||||||
|
this.exception = null;
|
||||||
|
} else {
|
||||||
|
this.exception = in.readException();
|
||||||
|
this.response = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
|
if (response != null) {
|
||||||
|
out.writeBoolean(true);
|
||||||
|
response.writeTo(out);
|
||||||
|
} else {
|
||||||
|
out.writeBoolean(false);
|
||||||
|
out.writeException(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is it a failed search?
|
* Is it a failed search?
|
||||||
*/
|
*/
|
||||||
|
@ -96,47 +114,25 @@ public class MultiSearchResponse extends ActionResponse implements Iterable<Mult
|
||||||
return this.response;
|
return this.response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Item readItem(StreamInput in) throws IOException {
|
|
||||||
Item item = new Item();
|
|
||||||
item.readFrom(in);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
|
||||||
if (in.readBoolean()) {
|
|
||||||
this.response = new SearchResponse();
|
|
||||||
response.readFrom(in);
|
|
||||||
} else {
|
|
||||||
exception = in.readException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
|
||||||
if (response != null) {
|
|
||||||
out.writeBoolean(true);
|
|
||||||
response.writeTo(out);
|
|
||||||
} else {
|
|
||||||
out.writeBoolean(false);
|
|
||||||
out.writeException(exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Exception getFailure() {
|
public Exception getFailure() {
|
||||||
return exception;
|
return exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Item[] items;
|
private final Item[] items;
|
||||||
|
private final long tookInMillis;
|
||||||
private long tookInMillis;
|
|
||||||
|
|
||||||
MultiSearchResponse() {
|
|
||||||
}
|
|
||||||
|
|
||||||
MultiSearchResponse(StreamInput in) throws IOException {
|
MultiSearchResponse(StreamInput in) throws IOException {
|
||||||
readFrom(in);
|
super(in);
|
||||||
|
items = new Item[in.readVInt()];
|
||||||
|
for (int i = 0; i < items.length; i++) {
|
||||||
|
items[i] = new Item(in);
|
||||||
|
}
|
||||||
|
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
|
||||||
|
tookInMillis = in.readVLong();
|
||||||
|
} else {
|
||||||
|
tookInMillis = 0L;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiSearchResponse(Item[] items, long tookInMillis) {
|
public MultiSearchResponse(Item[] items, long tookInMillis) {
|
||||||
|
@ -165,14 +161,7 @@ public class MultiSearchResponse extends ActionResponse implements Iterable<Mult
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
super.readFrom(in);
|
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
|
||||||
items = new Item[in.readVInt()];
|
|
||||||
for (int i = 0; i < items.length; i++) {
|
|
||||||
items[i] = Item.readItem(in);
|
|
||||||
}
|
|
||||||
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
|
|
||||||
tookInMillis = in.readVLong();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue