Skip to content

Commit

Permalink
iter
Browse files Browse the repository at this point in the history
  • Loading branch information
javanna committed Apr 3, 2024
1 parent f0ae51a commit 50215c5
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import org.elasticsearch.search.fetch.StoredFieldsSpec;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

/**
* A fetch sub-phase for high-level field retrieval. Given a list of fields, it
Expand Down Expand Up @@ -53,18 +53,21 @@ public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) {
? null
: FieldFetcher.create(fetchContext.getSearchExecutionContext(), fetchFieldsContext.fields());

FieldFetcher fieldFetcherMetadataFields = storedFieldsContext == null || storedFieldsContext.fetchFields() == false
? null
: FieldFetcher.create(
fetchContext.getSearchExecutionContext(),
Stream.concat(
METADATA_FIELDS.stream(),
storedFieldsContext.fieldNames()
.stream()
.filter(s -> fetchContext.getSearchExecutionContext().isMetadataField(s))
.map(s -> new FieldAndFormat(s, null))
).toList()
);
final FieldFetcher fieldFetcherMetadataFields;
if (storedFieldsContext == null || storedFieldsContext.fetchFields() == false) {
fieldFetcherMetadataFields = null;
} else {
List<FieldAndFormat> fields;
if (storedFieldsContext.fieldNames() == null) {
fields = METADATA_FIELDS;
} else {
fields = new ArrayList<>(METADATA_FIELDS);
for (String fieldName : storedFieldsContext.fieldNames()) {
fields.add(new FieldAndFormat(fieldName, null));
}
}
fieldFetcherMetadataFields = FieldFetcher.create(fetchContext.getSearchExecutionContext(), fields);
}

return new FetchSubPhaseProcessor() {
@Override
Expand Down

0 comments on commit 50215c5

Please sign in to comment.