Skip to content

Commit

Permalink
Use sequential reader for nested stored fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczi committed Oct 1, 2024
1 parent 1cfb6e8 commit ee68cdf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package org.elasticsearch.benchmark.search;public class SourceLoaderBenchmark {
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,24 @@ public static StoredFieldLoader fromSpec(StoredFieldsSpec spec) {
return create(spec.requiresSource(), spec.requiredStoredFields());
}

public static StoredFieldLoader create(boolean loadSource, Set<String> fields) {
return create(loadSource, fields, false);
}

/**
* Creates a new StoredFieldLoader
* @param loadSource should this loader load the _source field
* @param fields a set of additional fields the loader should load
*
* @param loadSource indicates whether this loader should load the {@code _source} field.
* @param fields a set of additional fields that the loader should load.
* @param forceSequentialReader if {@code true}, forces the use of a sequential leaf reader;
* otherwise, uses the heuristic defined in {@link StoredFieldLoader#reader(LeafReaderContext, int[])}.
*/
public static StoredFieldLoader create(boolean loadSource, Set<String> fields) {
public static StoredFieldLoader create(boolean loadSource, Set<String> fields, boolean forceSequentialReader) {
List<String> fieldsToLoad = fieldsToLoad(loadSource, fields);
return new StoredFieldLoader() {
@Override
public LeafStoredFieldLoader getLoader(LeafReaderContext ctx, int[] docs) throws IOException {
return new ReaderStoredFieldLoader(reader(ctx, docs), loadSource, fields);
return new ReaderStoredFieldLoader(forceSequentialReader ? sequentialReader(ctx) : reader(ctx, docs), loadSource, fields);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ SourceLoader.SyntheticFieldLoader syntheticFieldLoader(SourceFilter filter, Coll
SourceLoader sourceLoader = new SourceLoader.Synthetic(() -> super.syntheticFieldLoader(filter, mappers, true), NOOP);
// Some synthetic source use cases require using _ignored_source field
var requiredStoredFields = IgnoredSourceFieldMapper.ensureLoaded(sourceLoader.requiredStoredFields(), indexSettings);
var storedFieldLoader = org.elasticsearch.index.fieldvisitor.StoredFieldLoader.create(false, requiredStoredFields);
// force sequential access since nested fields are indexed per block
var storedFieldLoader = org.elasticsearch.index.fieldvisitor.StoredFieldLoader.create(false, requiredStoredFields, true);
return new NestedSyntheticFieldLoader(
storedFieldLoader,
sourceLoader,
Expand Down

0 comments on commit ee68cdf

Please sign in to comment.