20
20
package org .elasticsearch .script .mustache ;
21
21
22
22
import org .elasticsearch .ElasticsearchException ;
23
+ import org .elasticsearch .Version ;
23
24
import org .elasticsearch .action .ActionResponse ;
24
25
import org .elasticsearch .common .Nullable ;
25
26
import org .elasticsearch .common .Strings ;
26
27
import org .elasticsearch .common .io .stream .StreamInput ;
27
28
import org .elasticsearch .common .io .stream .StreamOutput ;
28
29
import org .elasticsearch .common .io .stream .Streamable ;
30
+ import org .elasticsearch .common .unit .TimeValue ;
29
31
import org .elasticsearch .common .xcontent .ToXContent ;
30
32
import org .elasticsearch .common .xcontent .ToXContentObject ;
31
33
import org .elasticsearch .common .xcontent .XContentBuilder ;
@@ -107,12 +109,14 @@ public Exception getFailure() {
107
109
}
108
110
109
111
private Item [] items ;
110
-
112
+ private long tookInMillis ;
113
+
111
114
MultiSearchTemplateResponse () {
112
115
}
113
116
114
- public MultiSearchTemplateResponse (Item [] items ) {
117
+ public MultiSearchTemplateResponse (Item [] items , long tookInMillis ) {
115
118
this .items = items ;
119
+ this .tookInMillis = tookInMillis ;
116
120
}
117
121
118
122
@ Override
@@ -126,6 +130,13 @@ public Iterator<Item> iterator() {
126
130
public Item [] getResponses () {
127
131
return this .items ;
128
132
}
133
+
134
+ /**
135
+ * How long the msearch_template took.
136
+ */
137
+ public TimeValue getTook () {
138
+ return new TimeValue (tookInMillis );
139
+ }
129
140
130
141
@ Override
131
142
public void readFrom (StreamInput in ) throws IOException {
@@ -134,6 +145,9 @@ public void readFrom(StreamInput in) throws IOException {
134
145
for (int i = 0 ; i < items .length ; i ++) {
135
146
items [i ] = Item .readItem (in );
136
147
}
148
+ if (in .getVersion ().onOrAfter (Version .V_7_0_0_alpha1 )) {
149
+ tookInMillis = in .readVLong ();
150
+ }
137
151
}
138
152
139
153
@ Override
@@ -143,11 +157,15 @@ public void writeTo(StreamOutput out) throws IOException {
143
157
for (Item item : items ) {
144
158
item .writeTo (out );
145
159
}
160
+ if (out .getVersion ().onOrAfter (Version .V_7_0_0_alpha1 )) {
161
+ out .writeVLong (tookInMillis );
162
+ }
146
163
}
147
164
148
165
@ Override
149
166
public XContentBuilder toXContent (XContentBuilder builder , ToXContent .Params params ) throws IOException {
150
167
builder .startObject ();
168
+ builder .field ("took" , tookInMillis );
151
169
builder .startArray (Fields .RESPONSES );
152
170
for (Item item : items ) {
153
171
if (item .isFailure ()) {
0 commit comments