3131import org .elasticsearch .index .IndexVersions ;
3232import org .elasticsearch .index .mapper .TimeSeriesRoutingHashFieldMapper ;
3333import org .elasticsearch .ingest .ESONIndexed ;
34- import org .elasticsearch .ingest .ESONXContentParser ;
34+ import org .elasticsearch .search .lookup .Source ;
35+ import org .elasticsearch .search .lookup .SourceFilter ;
3536import org .elasticsearch .transport .Transports ;
3637import org .elasticsearch .xcontent .DeprecationHandler ;
3738import org .elasticsearch .xcontent .NamedXContentRegistry ;
4041import org .elasticsearch .xcontent .XContentParserConfiguration ;
4142import org .elasticsearch .xcontent .XContentString ;
4243import org .elasticsearch .xcontent .XContentType ;
44+ import org .elasticsearch .xcontent .support .MapXContentParser ;
4345
4446import java .io .IOException ;
4547import java .util .ArrayList ;
@@ -312,6 +314,7 @@ public static class ExtractFromSource extends IndexRouting {
312314 private final IndexMode indexMode ;
313315 private final boolean trackTimeSeriesRoutingHash ;
314316 private final boolean addIdWithRoutingHash ;
317+ private final SourceFilter sourceFilter ;
315318 private int hash = Integer .MAX_VALUE ;
316319
317320 ExtractFromSource (IndexMetadata metadata ) {
@@ -326,6 +329,7 @@ public static class ExtractFromSource extends IndexRouting {
326329 List <String > routingPaths = metadata .getRoutingPaths ();
327330 isRoutingPath = Regex .simpleMatcher (routingPaths .toArray (String []::new ));
328331 this .parserConfig = XContentParserConfiguration .EMPTY .withFiltering (null , Set .copyOf (routingPaths ), null , true );
332+ sourceFilter = new SourceFilter (routingPaths .toArray (new String [0 ]), Strings .EMPTY_ARRAY );
329333 }
330334
331335 public boolean matchesField (String fieldName ) {
@@ -357,12 +361,12 @@ public int indexShard(String id, @Nullable String routing, XContentType sourceTy
357361 public int indexShard (String id , @ Nullable String routing , XContentType sourceType , ESONIndexed .ESONObject structuredSource ) {
358362 assert Transports .assertNotTransportThread ("parsing the _source can get slow" );
359363 checkNoRouting (routing );
360- // TODO: ESONFlat will return an unmutated version whereas Indexed can be mutated right now.
364+ Source source = Source . fromMap ( structuredSource , sourceType ). filter ( sourceFilter );
361365 try (
362- XContentParser parser = new ESONXContentParser (
363- structuredSource .esonFlat (),
366+ XContentParser parser = new MapXContentParser (
364367 NamedXContentRegistry .EMPTY ,
365368 DeprecationHandler .IGNORE_DEPRECATIONS ,
369+ source .source (),
366370 sourceType
367371 )
368372 ) {
0 commit comments