Skip to content

Commit

Permalink
Standardize naming of fetch subphases. (elastic#52171)
Browse files Browse the repository at this point in the history
This commit makes the names of fetch subphases more consistent:
* Now the names end in just 'Phase', whereas before some ended in
  'FetchSubPhase'. This matches the query subphases like AggregationPhase.
* Some names include 'fetch' like FetchScorePhase to avoid ambiguity about what
  they do.
  • Loading branch information
jtibshirani committed Feb 13, 2020
1 parent 4e28d40 commit ad01f07
Show file tree
Hide file tree
Showing 29 changed files with 88 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.elasticsearch.search.builder.SearchSourceBuilder.ScriptField;
import org.elasticsearch.search.collapse.CollapseBuilder;
import org.elasticsearch.search.fetch.StoredFieldsContext;
import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext.FieldAndFormat;
import org.elasticsearch.search.fetch.subphase.FetchDocValuesContext.FieldAndFormat;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.sort.SortBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.script.FieldScript;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext;
import org.elasticsearch.search.fetch.subphase.FetchDocValuesContext;
import org.elasticsearch.search.fetch.subphase.InnerHitsContext;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.search.sort.SortAndFormats;
Expand Down Expand Up @@ -88,7 +88,7 @@ protected void setupInnerHitsContext(QueryShardContext queryShardContext,
innerHitsContext.storedFieldsContext(innerHitBuilder.getStoredFieldsContext());
}
if (innerHitBuilder.getDocValueFields() != null) {
innerHitsContext.docValueFieldsContext(new DocValueFieldsContext(innerHitBuilder.getDocValueFields()));
innerHitsContext.docValuesContext(new FetchDocValuesContext(innerHitBuilder.getDocValueFields()));
}
if (innerHitBuilder.getScriptFields() != null) {
for (SearchSourceBuilder.ScriptField field : innerHitBuilder.getScriptFields()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import org.elasticsearch.search.fetch.FetchPhase;
import org.elasticsearch.search.fetch.FetchSearchResult;
import org.elasticsearch.search.fetch.StoredFieldsContext;
import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext;
import org.elasticsearch.search.fetch.subphase.FetchDocValuesContext;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.fetch.subphase.ScriptFieldsContext;
import org.elasticsearch.search.fetch.subphase.highlight.SearchContextHighlight;
Expand Down Expand Up @@ -111,7 +111,7 @@ final class DefaultSearchContext extends SearchContext {
private StoredFieldsContext storedFields;
private ScriptFieldsContext scriptFields;
private FetchSourceContext fetchSourceContext;
private DocValueFieldsContext docValueFieldsContext;
private FetchDocValuesContext docValuesContext;
private int from = -1;
private int size = -1;
private SortAndFormats sort;
Expand Down Expand Up @@ -459,13 +459,13 @@ public SearchContext fetchSourceContext(FetchSourceContext fetchSourceContext) {
}

@Override
public DocValueFieldsContext docValueFieldsContext() {
return docValueFieldsContext;
public FetchDocValuesContext docValuesContext() {
return docValuesContext;
}

@Override
public SearchContext docValueFieldsContext(DocValueFieldsContext docValueFieldsContext) {
this.docValueFieldsContext = docValueFieldsContext;
public SearchContext docValuesContext(FetchDocValuesContext docValuesContext) {
this.docValuesContext = docValuesContext;
return this;
}

Expand Down
32 changes: 16 additions & 16 deletions server/src/main/java/org/elasticsearch/search/SearchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,14 @@
import org.elasticsearch.search.aggregations.pipeline.SumBucketPipelineAggregator;
import org.elasticsearch.search.fetch.FetchPhase;
import org.elasticsearch.search.fetch.FetchSubPhase;
import org.elasticsearch.search.fetch.subphase.DocValueFieldsFetchSubPhase;
import org.elasticsearch.search.fetch.subphase.ExplainFetchSubPhase;
import org.elasticsearch.search.fetch.subphase.FetchSourceSubPhase;
import org.elasticsearch.search.fetch.subphase.MatchedQueriesFetchSubPhase;
import org.elasticsearch.search.fetch.subphase.ScoreFetchSubPhase;
import org.elasticsearch.search.fetch.subphase.ScriptFieldsFetchSubPhase;
import org.elasticsearch.search.fetch.subphase.SeqNoPrimaryTermFetchSubPhase;
import org.elasticsearch.search.fetch.subphase.VersionFetchSubPhase;
import org.elasticsearch.search.fetch.subphase.FetchDocValuesPhase;
import org.elasticsearch.search.fetch.subphase.ExplainPhase;
import org.elasticsearch.search.fetch.subphase.FetchSourcePhase;
import org.elasticsearch.search.fetch.subphase.MatchedQueriesPhase;
import org.elasticsearch.search.fetch.subphase.FetchScorePhase;
import org.elasticsearch.search.fetch.subphase.ScriptFieldsPhase;
import org.elasticsearch.search.fetch.subphase.SeqNoPrimaryTermPhase;
import org.elasticsearch.search.fetch.subphase.FetchVersionPhase;
import org.elasticsearch.search.fetch.subphase.highlight.FastVectorHighlighter;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightPhase;
import org.elasticsearch.search.fetch.subphase.highlight.Highlighter;
Expand Down Expand Up @@ -745,15 +745,15 @@ private void registerMovingAverageModel(SearchExtensionSpec<MovAvgModel, MovAvgM
}

private void registerFetchSubPhases(List<SearchPlugin> plugins) {
registerFetchSubPhase(new ExplainFetchSubPhase());
registerFetchSubPhase(new DocValueFieldsFetchSubPhase());
registerFetchSubPhase(new ScriptFieldsFetchSubPhase());
registerFetchSubPhase(new FetchSourceSubPhase());
registerFetchSubPhase(new VersionFetchSubPhase());
registerFetchSubPhase(new SeqNoPrimaryTermFetchSubPhase());
registerFetchSubPhase(new MatchedQueriesFetchSubPhase());
registerFetchSubPhase(new ExplainPhase());
registerFetchSubPhase(new FetchDocValuesPhase());
registerFetchSubPhase(new ScriptFieldsPhase());
registerFetchSubPhase(new FetchSourcePhase());
registerFetchSubPhase(new FetchVersionPhase());
registerFetchSubPhase(new SeqNoPrimaryTermPhase());
registerFetchSubPhase(new MatchedQueriesPhase());
registerFetchSubPhase(new HighlightPhase(highlighters));
registerFetchSubPhase(new ScoreFetchSubPhase());
registerFetchSubPhase(new FetchScorePhase());

FetchPhaseConstructionContext context = new FetchPhaseConstructionContext(highlighters);
registerFromPlugin(plugins, p -> p.getFetchSubPhases(context), this::registerFetchSubPhase);
Expand Down
10 changes: 5 additions & 5 deletions server/src/main/java/org/elasticsearch/search/SearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
import org.elasticsearch.search.fetch.QueryFetchSearchResult;
import org.elasticsearch.search.fetch.ScrollQueryFetchSearchResult;
import org.elasticsearch.search.fetch.ShardFetchRequest;
import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext;
import org.elasticsearch.search.fetch.subphase.FetchDocValuesContext;
import org.elasticsearch.search.fetch.subphase.ScriptFieldsContext.ScriptField;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.internal.AliasFilter;
Expand Down Expand Up @@ -822,11 +822,11 @@ private void parseSource(DefaultSearchContext context, SearchSourceBuilder sourc
context.fetchSourceContext(source.fetchSource());
}
if (source.docValueFields() != null) {
List<DocValueFieldsContext.FieldAndFormat> docValueFields = new ArrayList<>();
for (DocValueFieldsContext.FieldAndFormat format : source.docValueFields()) {
List<FetchDocValuesContext.FieldAndFormat> docValueFields = new ArrayList<>();
for (FetchDocValuesContext.FieldAndFormat format : source.docValueFields()) {
Collection<String> fieldNames = context.mapperService().simpleMatchToFullName(format.field);
for (String fieldName: fieldNames) {
docValueFields.add(new DocValueFieldsContext.FieldAndFormat(fieldName, format.format));
docValueFields.add(new FetchDocValuesContext.FieldAndFormat(fieldName, format.format));
}
}
int maxAllowedDocvalueFields = context.mapperService().getIndexSettings().getMaxDocvalueFields();
Expand All @@ -836,7 +836,7 @@ private void parseSource(DefaultSearchContext context, SearchSourceBuilder sourc
+ "] but was [" + docValueFields.size() + "]. This limit can be set by changing the ["
+ IndexSettings.MAX_DOCVALUE_FIELDS_SEARCH_SETTING.getKey() + "] index level setting.");
}
context.docValueFieldsContext(new DocValueFieldsContext(docValueFields));
context.docValuesContext(new FetchDocValuesContext(docValueFields));
}
if (source.highlighter() != null) {
HighlightBuilder highlightBuilder = source.highlighter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder.ScriptField;
import org.elasticsearch.search.fetch.StoredFieldsContext;
import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext.FieldAndFormat;
import org.elasticsearch.search.fetch.subphase.FetchDocValuesContext.FieldAndFormat;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.fetch.subphase.ScriptFieldsContext;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.fetch.StoredFieldsContext;
import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext;
import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext.FieldAndFormat;
import org.elasticsearch.search.fetch.subphase.FetchDocValuesContext;
import org.elasticsearch.search.fetch.subphase.FetchDocValuesContext.FieldAndFormat;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.fetch.subphase.ScriptFieldsContext;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
Expand Down Expand Up @@ -107,7 +107,7 @@ public Aggregator createInternal(SearchContext searchContext,
subSearchContext.storedFieldsContext(storedFieldsContext);
}
if (docValueFields != null) {
subSearchContext.docValueFieldsContext(new DocValueFieldsContext(docValueFields));
subSearchContext.docValuesContext(new FetchDocValuesContext(docValueFields));
}
for (ScriptFieldsContext.ScriptField field : scriptFields) {
subSearchContext.scriptFields().add(field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.elasticsearch.search.aggregations.PipelineAggregationBuilder;
import org.elasticsearch.search.collapse.CollapseBuilder;
import org.elasticsearch.search.fetch.StoredFieldsContext;
import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext.FieldAndFormat;
import org.elasticsearch.search.fetch.subphase.FetchDocValuesContext.FieldAndFormat;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.internal.SearchContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import org.elasticsearch.search.SearchShardTarget;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.fetch.subphase.InnerHitsContext;
import org.elasticsearch.search.fetch.subphase.InnerHitsFetchSubPhase;
import org.elasticsearch.search.fetch.subphase.InnerHitsPhase;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.search.lookup.SourceLookup;
import org.elasticsearch.tasks.TaskCancelledException;
Expand All @@ -81,7 +81,7 @@ public class FetchPhase implements SearchPhase {

public FetchPhase(List<FetchSubPhase> fetchSubPhases) {
this.fetchSubPhases = fetchSubPhases.toArray(new FetchSubPhase[fetchSubPhases.size() + 1]);
this.fetchSubPhases[fetchSubPhases.size()] = new InnerHitsFetchSubPhase(this);
this.fetchSubPhases[fetchSubPhases.size()] = new InnerHitsPhase(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* Explains the scoring calculations for the top hits.
*/
public final class ExplainFetchSubPhase implements FetchSubPhase {
public final class ExplainPhase implements FetchSubPhase {

@Override
public void hitExecute(SearchContext context, HitContext hitContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/**
* All the required context to pull a field from the doc values.
*/
public class DocValueFieldsContext {
public class FetchDocValuesContext {

/**
* Wrapper around a field name and the format that should be used to
Expand Down Expand Up @@ -113,7 +113,7 @@ public boolean equals(Object obj) {

private final List<FieldAndFormat> fields;

public DocValueFieldsContext(List<FieldAndFormat> fields) {
public FetchDocValuesContext(List<FieldAndFormat> fields) {
this.fields = fields;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.fetch.FetchSubPhase;
import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext.FieldAndFormat;
import org.elasticsearch.search.fetch.subphase.FetchDocValuesContext.FieldAndFormat;
import org.elasticsearch.search.internal.SearchContext;

import java.io.IOException;
Expand All @@ -51,38 +51,38 @@
import static org.elasticsearch.search.DocValueFormat.withNanosecondResolution;

/**
* Query sub phase which pulls data from doc values
* Fetch sub phase which pulls data from doc values.
*
* Specifying {@code "docvalue_fields": ["field1", "field2"]}
*/
public final class DocValueFieldsFetchSubPhase implements FetchSubPhase {
public final class FetchDocValuesPhase implements FetchSubPhase {

private static final String USE_DEFAULT_FORMAT = "use_field_mapping";
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(
LogManager.getLogger(DocValueFieldsFetchSubPhase.class));
LogManager.getLogger(FetchDocValuesPhase.class));

@Override
public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOException {

if (context.collapse() != null) {
// retrieve the `doc_value` associated with the collapse field
String name = context.collapse().getFieldName();
if (context.docValueFieldsContext() == null) {
context.docValueFieldsContext(new DocValueFieldsContext(
if (context.docValuesContext() == null) {
context.docValuesContext(new FetchDocValuesContext(
Collections.singletonList(new FieldAndFormat(name, null))));
} else if (context.docValueFieldsContext().fields().stream().map(ff -> ff.field).anyMatch(name::equals) == false) {
context.docValueFieldsContext().fields().add(new FieldAndFormat(name, null));
} else if (context.docValuesContext().fields().stream().map(ff -> ff.field).anyMatch(name::equals) == false) {
context.docValuesContext().fields().add(new FieldAndFormat(name, null));
}
}

if (context.docValueFieldsContext() == null) {
if (context.docValuesContext() == null) {
return;
}

hits = hits.clone(); // don't modify the incoming hits
Arrays.sort(hits, Comparator.comparingInt(SearchHit::docId));

if (context.docValueFieldsContext().fields().stream()
if (context.docValuesContext().fields().stream()
.map(f -> f.format)
.filter(USE_DEFAULT_FORMAT::equals)
.findAny()
Expand All @@ -91,7 +91,7 @@ public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOExcept
"ease the transition to 7.x. It has become the default and shouldn't be set explicitly anymore.");
}

for (FieldAndFormat fieldAndFormat : context.docValueFieldsContext().fields()) {
for (FieldAndFormat fieldAndFormat : context.docValuesContext().fields()) {
String field = fieldAndFormat.field;
MappedFieldType fieldType = context.mapperService().fieldType(field);
if (fieldType != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.Comparator;
import java.util.Iterator;

public class ScoreFetchSubPhase implements FetchSubPhase {
public class FetchScorePhase implements FetchSubPhase {

@Override
public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.io.IOException;
import java.util.Map;

public final class FetchSourceSubPhase implements FetchSubPhase {
public final class FetchSourcePhase implements FetchSubPhase {

@Override
public void hitExecute(SearchContext context, HitContext hitContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.util.Arrays;
import java.util.Comparator;

public final class VersionFetchSubPhase implements FetchSubPhase {
public final class FetchVersionPhase implements FetchSubPhase {
@Override
public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOException {
if (context.version() == false ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
import java.util.HashMap;
import java.util.Map;

public final class InnerHitsFetchSubPhase implements FetchSubPhase {
public final class InnerHitsPhase implements FetchSubPhase {

private final FetchPhase fetchPhase;

public InnerHitsFetchSubPhase(FetchPhase fetchPhase) {
public InnerHitsPhase(FetchPhase fetchPhase) {
this.fetchPhase = fetchPhase;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import java.util.List;
import java.util.Map;

public final class MatchedQueriesFetchSubPhase implements FetchSubPhase {
public final class MatchedQueriesPhase implements FetchSubPhase {

@Override
public void hitsExecute(SearchContext context, SearchHit[] hits) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import java.util.HashMap;
import java.util.List;

public final class ScriptFieldsFetchSubPhase implements FetchSubPhase {
public final class ScriptFieldsPhase implements FetchSubPhase {

@Override
public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOException {
Expand Down Expand Up @@ -65,7 +65,7 @@ public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOExcept
final Object value;
try {
value = leafScripts[i].execute();
CollectionUtils.ensureNoSelfReferences(value, "ScriptFieldsFetchSubPhase leaf script " + i);
CollectionUtils.ensureNoSelfReferences(value, "ScriptFieldsPhase leaf script " + i);
} catch (RuntimeException e) {
if (scriptFields.get(i).ignoreException()) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.util.Arrays;
import java.util.Comparator;

public final class SeqNoPrimaryTermFetchSubPhase implements FetchSubPhase {
public final class SeqNoPrimaryTermPhase implements FetchSubPhase {
@Override
public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOException {
if (context.seqNoAndPrimaryTerm() == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.elasticsearch.search.fetch.FetchPhase;
import org.elasticsearch.search.fetch.FetchSearchResult;
import org.elasticsearch.search.fetch.StoredFieldsContext;
import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext;
import org.elasticsearch.search.fetch.subphase.FetchDocValuesContext;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.fetch.subphase.InnerHitsContext;
import org.elasticsearch.search.fetch.subphase.ScriptFieldsContext;
Expand Down Expand Up @@ -197,9 +197,9 @@ public InnerHitsContext innerHits() {

public abstract SearchContext fetchSourceContext(FetchSourceContext fetchSourceContext);

public abstract DocValueFieldsContext docValueFieldsContext();
public abstract FetchDocValuesContext docValuesContext();

public abstract SearchContext docValueFieldsContext(DocValueFieldsContext docValueFieldsContext);
public abstract SearchContext docValuesContext(FetchDocValuesContext docValuesContext);

public abstract ContextIndexSearcher searcher();

Expand Down
Loading

0 comments on commit ad01f07

Please sign in to comment.