38
38
import org .elasticsearch .xpack .core .ml .job .results .ForecastRequestStats ;
39
39
import org .elasticsearch .xpack .core .ml .job .results .Influencer ;
40
40
import org .elasticsearch .xpack .core .ml .job .results .ModelPlot ;
41
+ import org .elasticsearch .xpack .core .ml .utils .ToXContentParams ;
41
42
42
43
import java .io .IOException ;
43
44
import java .util .Collections ;
@@ -130,7 +131,11 @@ private void persistBucketInfluencersStandalone(String jobId, List<BucketInfluen
130
131
* @return this
131
132
*/
132
133
public Builder persistTimingStats (TimingStats timingStats ) {
133
- indexResult (TimingStats .documentId (timingStats .getJobId ()), timingStats , TimingStats .TYPE .getPreferredName ());
134
+ indexResult (
135
+ TimingStats .documentId (timingStats .getJobId ()),
136
+ timingStats ,
137
+ new ToXContent .MapParams (Collections .singletonMap (ToXContentParams .FOR_INTERNAL_STORAGE , "true" )),
138
+ TimingStats .TYPE .getPreferredName ());
134
139
return this ;
135
140
}
136
141
@@ -185,7 +190,11 @@ public Builder persistForecastRequestStats(ForecastRequestStats forecastRequestS
185
190
}
186
191
187
192
private void indexResult (String id , ToXContent resultDoc , String resultType ) {
188
- try (XContentBuilder content = toXContentBuilder (resultDoc )) {
193
+ indexResult (id , resultDoc , ToXContent .EMPTY_PARAMS , resultType );
194
+ }
195
+
196
+ private void indexResult (String id , ToXContent resultDoc , ToXContent .Params params , String resultType ) {
197
+ try (XContentBuilder content = toXContentBuilder (resultDoc , params )) {
189
198
bulkRequest .add (new IndexRequest (indexName ).id (id ).source (content ));
190
199
} catch (IOException e ) {
191
200
logger .error (new ParameterizedMessage ("[{}] Error serialising {}" , jobId , resultType ), e );
@@ -335,27 +344,37 @@ public void commitStateWrites(String jobId) {
335
344
public IndexResponse persistDatafeedTimingStats (DatafeedTimingStats timingStats , WriteRequest .RefreshPolicy refreshPolicy ) {
336
345
String jobId = timingStats .getJobId ();
337
346
logger .trace ("[{}] Persisting datafeed timing stats" , jobId );
338
- Persistable persistable = new Persistable (jobId , timingStats , DatafeedTimingStats .documentId (timingStats .getJobId ()));
347
+ Persistable persistable = new Persistable (
348
+ jobId ,
349
+ timingStats ,
350
+ new ToXContent .MapParams (Collections .singletonMap (ToXContentParams .FOR_INTERNAL_STORAGE , "true" )),
351
+ DatafeedTimingStats .documentId (timingStats .getJobId ()));
339
352
persistable .setRefreshPolicy (refreshPolicy );
340
353
return persistable .persist (AnomalyDetectorsIndex .resultsWriteAlias (jobId )).actionGet ();
341
354
}
342
355
343
- private XContentBuilder toXContentBuilder (ToXContent obj ) throws IOException {
356
+ private static XContentBuilder toXContentBuilder (ToXContent obj , ToXContent . Params params ) throws IOException {
344
357
XContentBuilder builder = jsonBuilder ();
345
- obj .toXContent (builder , ToXContent . EMPTY_PARAMS );
358
+ obj .toXContent (builder , params );
346
359
return builder ;
347
360
}
348
361
349
362
private class Persistable {
350
363
351
364
private final String jobId ;
352
365
private final ToXContent object ;
366
+ private final ToXContent .Params params ;
353
367
private final String id ;
354
368
private WriteRequest .RefreshPolicy refreshPolicy ;
355
369
356
370
Persistable (String jobId , ToXContent object , String id ) {
371
+ this (jobId , object , ToXContent .EMPTY_PARAMS , id );
372
+ }
373
+
374
+ Persistable (String jobId , ToXContent object , ToXContent .Params params , String id ) {
357
375
this .jobId = jobId ;
358
376
this .object = object ;
377
+ this .params = params ;
359
378
this .id = id ;
360
379
this .refreshPolicy = WriteRequest .RefreshPolicy .NONE ;
361
380
}
@@ -373,7 +392,7 @@ ActionFuture<IndexResponse> persist(String indexName) {
373
392
void persist (String indexName , ActionListener <IndexResponse > listener ) {
374
393
logCall (indexName );
375
394
376
- try (XContentBuilder content = toXContentBuilder (object )) {
395
+ try (XContentBuilder content = toXContentBuilder (object , params )) {
377
396
IndexRequest indexRequest = new IndexRequest (indexName ).id (id ).source (content ).setRefreshPolicy (refreshPolicy );
378
397
executeAsyncWithOrigin (client .threadPool ().getThreadContext (), ML_ORIGIN , indexRequest , listener , client ::index );
379
398
} catch (IOException e ) {
0 commit comments