2020package org .elasticsearch .script .mustache ;
2121
2222import org .elasticsearch .ElasticsearchException ;
23+ import org .elasticsearch .Version ;
2324import org .elasticsearch .action .ActionResponse ;
2425import org .elasticsearch .common .Nullable ;
2526import org .elasticsearch .common .Strings ;
2627import org .elasticsearch .common .io .stream .StreamInput ;
2728import org .elasticsearch .common .io .stream .StreamOutput ;
2829import org .elasticsearch .common .io .stream .Streamable ;
30+ import org .elasticsearch .common .unit .TimeValue ;
2931import org .elasticsearch .common .xcontent .ToXContent ;
3032import org .elasticsearch .common .xcontent .ToXContentObject ;
3133import org .elasticsearch .common .xcontent .XContentBuilder ;
@@ -107,12 +109,14 @@ public Exception getFailure() {
107109 }
108110
109111 private Item [] items ;
110-
112+ private long tookInMillis ;
113+
111114 MultiSearchTemplateResponse () {
112115 }
113116
114- public MultiSearchTemplateResponse (Item [] items ) {
117+ public MultiSearchTemplateResponse (Item [] items , long tookInMillis ) {
115118 this .items = items ;
119+ this .tookInMillis = tookInMillis ;
116120 }
117121
118122 @ Override
@@ -126,6 +130,13 @@ public Iterator<Item> iterator() {
126130 public Item [] getResponses () {
127131 return this .items ;
128132 }
133+
134+ /**
135+ * How long the msearch_template took.
136+ */
137+ public TimeValue getTook () {
138+ return new TimeValue (tookInMillis );
139+ }
129140
130141 @ Override
131142 public void readFrom (StreamInput in ) throws IOException {
@@ -134,6 +145,9 @@ public void readFrom(StreamInput in) throws IOException {
134145 for (int i = 0 ; i < items .length ; i ++) {
135146 items [i ] = Item .readItem (in );
136147 }
148+ if (in .getVersion ().onOrAfter (Version .V_7_0_0_alpha1 )) {
149+ tookInMillis = in .readVLong ();
150+ }
137151 }
138152
139153 @ Override
@@ -143,11 +157,15 @@ public void writeTo(StreamOutput out) throws IOException {
143157 for (Item item : items ) {
144158 item .writeTo (out );
145159 }
160+ if (out .getVersion ().onOrAfter (Version .V_7_0_0_alpha1 )) {
161+ out .writeVLong (tookInMillis );
162+ }
146163 }
147164
148165 @ Override
149166 public XContentBuilder toXContent (XContentBuilder builder , ToXContent .Params params ) throws IOException {
150167 builder .startObject ();
168+ builder .field ("took" , tookInMillis );
151169 builder .startArray (Fields .RESPONSES );
152170 for (Item item : items ) {
153171 if (item .isFailure ()) {
0 commit comments