Skip to content

Commit 7c2925a

Browse files
committed
Routing
1 parent 360e368 commit 7c2925a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

server/src/main/java/org/elasticsearch/action/index/IndexRequest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -945,10 +945,8 @@ public Index getConcreteWriteIndex(IndexAbstraction ia, ProjectMetadata project)
945945
@Override
946946
public int route(IndexRouting indexRouting) {
947947
if (modernSource.isStructured()) {
948-
// TODO: Need to implement filtering
949-
// return indexRouting.indexShard(id, routing, contentType, structuredSource);
950948
if (indexRouting instanceof IndexRouting.ExtractFromSource) {
951-
return indexRouting.indexShard(id, routing, contentType, source());
949+
return indexRouting.indexShard(id, routing, contentType, ESONIndexed.fromFlat(modernSource.structuredSource()));
952950
} else {
953951
return indexRouting.indexShard(id, routing, contentType, (BytesReference) null);
954952
}

server/src/main/java/org/elasticsearch/cluster/routing/IndexRouting.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
import org.elasticsearch.index.IndexVersions;
3232
import org.elasticsearch.index.mapper.TimeSeriesRoutingHashFieldMapper;
3333
import org.elasticsearch.ingest.ESONIndexed;
34-
import org.elasticsearch.ingest.ESONXContentParser;
34+
import org.elasticsearch.search.lookup.Source;
35+
import org.elasticsearch.search.lookup.SourceFilter;
3536
import org.elasticsearch.transport.Transports;
3637
import org.elasticsearch.xcontent.DeprecationHandler;
3738
import org.elasticsearch.xcontent.NamedXContentRegistry;
@@ -40,6 +41,7 @@
4041
import org.elasticsearch.xcontent.XContentParserConfiguration;
4142
import org.elasticsearch.xcontent.XContentString;
4243
import org.elasticsearch.xcontent.XContentType;
44+
import org.elasticsearch.xcontent.support.MapXContentParser;
4345

4446
import java.io.IOException;
4547
import 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

Comments
 (0)