Skip to content

Commit 95582da

Browse files
authored
Rename QueryShardContext#fieldMapper to getFieldType (#63399)
Given that we have a class called `FieldMapper` and that the `fieldMapper` method exposed by `QueryShardContext` actually allows to get a `MappedFieldType` given its name, this commit renames such method to `getFieldType`
1 parent 2f1bc84 commit 95582da

File tree

72 files changed

+186
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+186
-187
lines changed

modules/mapper-extras/src/main/java/org/elasticsearch/index/query/RankFeatureQueryBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
import org.elasticsearch.common.io.stream.StreamOutput;
2828
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
2929
import org.elasticsearch.common.xcontent.XContentBuilder;
30+
import org.elasticsearch.index.mapper.MappedFieldType;
3031
import org.elasticsearch.index.mapper.RankFeatureFieldMapper.RankFeatureFieldType;
3132
import org.elasticsearch.index.mapper.RankFeatureMetaFieldMapper;
3233
import org.elasticsearch.index.mapper.RankFeaturesFieldMapper.RankFeaturesFieldType;
33-
import org.elasticsearch.index.mapper.MappedFieldType;
3434

3535
import java.io.IOException;
3636
import java.util.Arrays;
@@ -337,7 +337,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
337337

338338
@Override
339339
protected Query doToQuery(QueryShardContext context) throws IOException {
340-
final MappedFieldType ft = context.fieldMapper(field);
340+
final MappedFieldType ft = context.getFieldType(field);
341341

342342
if (ft instanceof RankFeatureFieldType) {
343343
final RankFeatureFieldType fft = (RankFeatureFieldType) ft;
@@ -346,7 +346,7 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
346346
final int lastDotIndex = field.lastIndexOf('.');
347347
if (lastDotIndex != -1) {
348348
final String parentField = field.substring(0, lastDotIndex);
349-
final MappedFieldType parentFt = context.fieldMapper(parentField);
349+
final MappedFieldType parentFt = context.getFieldType(parentField);
350350
if (parentFt instanceof RankFeaturesFieldType) {
351351
return scoreFunction.toQuery(parentField, field.substring(lastDotIndex + 1), true);
352352
}

modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
453453
throw new IllegalStateException("no document to percolate");
454454
}
455455

456-
MappedFieldType fieldType = context.fieldMapper(field);
456+
MappedFieldType fieldType = context.getFieldType(field);
457457
if (fieldType == null) {
458458
throw new QueryShardException(context, "field [" + field + "] does not exist");
459459
}

modules/percolator/src/test/java/org/elasticsearch/percolator/QueryBuilderStoreTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void testStoringQueryBuilders() throws IOException {
9595
when(queryShardContext.getXContentRegistry()).thenReturn(xContentRegistry());
9696
when(queryShardContext.getForField(fieldMapper.fieldType()))
9797
.thenReturn(new BytesBinaryIndexFieldData(fieldMapper.name(), CoreValuesSourceType.BYTES));
98-
when(queryShardContext.fieldMapper(Mockito.anyString())).thenAnswer(invocation -> {
98+
when(queryShardContext.getFieldType(Mockito.anyString())).thenAnswer(invocation -> {
9999
final String fieldName = (String) invocation.getArguments()[0];
100100
return new KeywordFieldMapper.KeywordFieldType(fieldName);
101101
});

plugins/examples/rescore/src/main/java/org/elasticsearch/example/rescore/ExampleRescoreBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
3232
import org.elasticsearch.common.xcontent.XContentBuilder;
3333
import org.elasticsearch.common.xcontent.XContentParser;
34+
import org.elasticsearch.index.fielddata.IndexFieldData;
3435
import org.elasticsearch.index.fielddata.LeafFieldData;
3536
import org.elasticsearch.index.fielddata.LeafNumericFieldData;
36-
import org.elasticsearch.index.fielddata.IndexFieldData;
3737
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
3838
import org.elasticsearch.index.query.QueryRewriteContext;
3939
import org.elasticsearch.index.query.QueryShardContext;
@@ -109,7 +109,7 @@ public static ExampleRescoreBuilder fromXContent(XContentParser parser) {
109109
@Override
110110
public RescoreContext innerBuildContext(int windowSize, QueryShardContext context) throws IOException {
111111
IndexFieldData<?> factorField =
112-
this.factorField == null ? null : context.getForField(context.fieldMapper(this.factorField));
112+
this.factorField == null ? null : context.getForField(context.getFieldType(this.factorField));
113113
return new ExampleRescoreContext(windowSize, factor, factorField);
114114
}
115115

server/src/main/java/org/elasticsearch/index/query/AbstractGeometryQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ protected Query doToQuery(QueryShardContext context) {
347347
if (shape == null || supplier != null) {
348348
throw new UnsupportedOperationException("query must be rewritten first");
349349
}
350-
final MappedFieldType fieldType = context.fieldMapper(fieldName);
350+
final MappedFieldType fieldType = context.getFieldType(fieldName);
351351
if (fieldType == null) {
352352
if (ignoreUnmapped) {
353353
return new MatchNoDocsQuery();

server/src/main/java/org/elasticsearch/index/query/DistanceFeatureQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public String getWriteableName() {
108108

109109
@Override
110110
protected Query doToQuery(QueryShardContext context) throws IOException {
111-
MappedFieldType fieldType = context.fieldMapper(field);
111+
MappedFieldType fieldType = context.getFieldType(field);
112112
if (fieldType == null) {
113113
return Queries.newMatchNoDocsQuery("Can't run [" + NAME + "] query on unmapped fields!");
114114
}

server/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static Query newFilter(QueryShardContext context, String fieldPattern, bo
165165

166166
private static Query newFieldExistsQuery(QueryShardContext context, String field) {
167167
if (context.isFieldMapped(field)) {
168-
Query filter = context.fieldMapper(field).existsQuery(context);
168+
Query filter = context.getFieldType(field).existsQuery(context);
169169
return new ConstantScoreQuery(filter);
170170
} else {
171171
// The field does not exist as a leaf but could be an object so
@@ -181,7 +181,7 @@ private static Query newObjectFieldExistsQuery(QueryShardContext context, String
181181
BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
182182
Collection<String> fields = context.simpleMatchToIndexNames(objField + ".*");
183183
for (String field : fields) {
184-
Query existsQuery = context.fieldMapper(field).existsQuery(context);
184+
Query existsQuery = context.getFieldType(field).existsQuery(context);
185185
booleanQuery.add(existsQuery, Occur.SHOULD);
186186
}
187187
return new ConstantScoreQuery(booleanQuery.build());

server/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public static FieldMaskingSpanQueryBuilder fromXContent(XContentParser parser) t
152152
@Override
153153
protected SpanQuery doToQuery(QueryShardContext context) throws IOException {
154154
String fieldInQuery = fieldName;
155-
MappedFieldType fieldType = context.fieldMapper(fieldName);
155+
MappedFieldType fieldType = context.getFieldType(fieldName);
156156
if (fieldType != null) {
157157
fieldInQuery = fieldType.name();
158158
}

server/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public String getWriteableName() {
324324
protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws IOException {
325325
QueryShardContext context = queryRewriteContext.convertToShardContext();
326326
if (context != null) {
327-
MappedFieldType fieldType = context.fieldMapper(fieldName);
327+
MappedFieldType fieldType = context.getFieldType(fieldName);
328328
if (fieldType == null) {
329329
return new MatchNoneQueryBuilder();
330330
}
@@ -334,7 +334,7 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws
334334

335335
@Override
336336
protected Query doToQuery(QueryShardContext context) throws IOException {
337-
MappedFieldType fieldType = context.fieldMapper(fieldName);
337+
MappedFieldType fieldType = context.getFieldType(fieldName);
338338
if (fieldType == null) {
339339
throw new IllegalStateException("Rewrite first");
340340
}

server/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ QueryValidationException checkLatLon() {
304304

305305
@Override
306306
public Query doToQuery(QueryShardContext context) {
307-
MappedFieldType fieldType = context.fieldMapper(fieldName);
307+
MappedFieldType fieldType = context.getFieldType(fieldName);
308308
if (fieldType == null) {
309309
if (ignoreUnmapped) {
310310
return new MatchNoDocsQuery();

server/src/main/java/org/elasticsearch/index/query/GeoDistanceQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public boolean ignoreUnmapped() {
227227

228228
@Override
229229
protected Query doToQuery(QueryShardContext shardContext) throws IOException {
230-
MappedFieldType fieldType = shardContext.fieldMapper(fieldName);
230+
MappedFieldType fieldType = shardContext.getFieldType(fieldName);
231231
if (fieldType == null) {
232232
if (ignoreUnmapped) {
233233
return new MatchNoDocsQuery();

server/src/main/java/org/elasticsearch/index/query/GeoPolygonQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public boolean ignoreUnmapped() {
153153

154154
@Override
155155
protected Query doToQuery(QueryShardContext context) throws IOException {
156-
MappedFieldType fieldType = context.fieldMapper(fieldName);
156+
MappedFieldType fieldType = context.getFieldType(fieldName);
157157
if (fieldType == null) {
158158
if (ignoreUnmapped) {
159159
return new MatchNoDocsQuery();

server/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws
140140
return new MatchNoneQueryBuilder();
141141
}
142142
QueryShardContext context = queryRewriteContext.convertToShardContext();
143-
if (context != null && context.fieldMapper(IdFieldMapper.NAME) == null) {
143+
if (context != null && context.getFieldType(IdFieldMapper.NAME) == null) {
144144
// no mappings yet
145145
return new MatchNoneQueryBuilder();
146146
}
@@ -149,7 +149,7 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws
149149

150150
@Override
151151
protected Query doToQuery(QueryShardContext context) throws IOException {
152-
MappedFieldType idField = context.fieldMapper(IdFieldMapper.NAME);
152+
MappedFieldType idField = context.getFieldType(IdFieldMapper.NAME);
153153
if (idField == null || ids.isEmpty()) {
154154
throw new IllegalStateException("Rewrite first");
155155
}

server/src/main/java/org/elasticsearch/index/query/IntervalQueryBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
package org.elasticsearch.index.query;
2121

22+
import org.apache.lucene.queries.intervals.IntervalQuery;
2223
import org.apache.lucene.search.MatchNoDocsQuery;
2324
import org.apache.lucene.search.Query;
24-
import org.apache.lucene.queries.intervals.IntervalQuery;
2525
import org.elasticsearch.common.ParsingException;
2626
import org.elasticsearch.common.io.stream.StreamInput;
2727
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -132,15 +132,15 @@ public static IntervalQueryBuilder fromXContent(XContentParser parser) throws IO
132132

133133
@Override
134134
protected Query doToQuery(QueryShardContext context) throws IOException {
135-
MappedFieldType fieldType = context.fieldMapper(field);
135+
MappedFieldType fieldType = context.getFieldType(field);
136136
if (fieldType == null) {
137137
// Be lenient with unmapped fields so that cross-index search will work nicely
138138
return new MatchNoDocsQuery();
139139
}
140140
Set<String> maskedFields = new HashSet<>();
141141
sourceProvider.extractFields(maskedFields);
142142
for (String maskedField : maskedFields) {
143-
MappedFieldType ft = context.fieldMapper(maskedField);
143+
MappedFieldType ft = context.getFieldType(maskedField);
144144
if (ft == null) {
145145
// Be lenient with unmapped fields so that cross-index search will work nicely
146146
return new MatchNoDocsQuery();

server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public IntervalsSource getSource(QueryShardContext context, MappedFieldType fiel
147147
}
148148
IntervalsSource source;
149149
if (useField != null) {
150-
fieldType = context.fieldMapper(useField);
150+
fieldType = context.getFieldType(useField);
151151
assert fieldType != null;
152152
source = Intervals.fixField(useField, fieldType.intervals(query, maxGaps, ordered, analyzer, false));
153153
}
@@ -530,7 +530,7 @@ public IntervalsSource getSource(QueryShardContext context, MappedFieldType fiel
530530
}
531531
IntervalsSource source;
532532
if (useField != null) {
533-
fieldType = context.fieldMapper(useField);
533+
fieldType = context.getFieldType(useField);
534534
assert fieldType != null;
535535
source = Intervals.fixField(useField, fieldType.intervals(prefix, 0, false, analyzer, true));
536536
}
@@ -645,7 +645,7 @@ public IntervalsSource getSource(QueryShardContext context, MappedFieldType fiel
645645
}
646646
IntervalsSource source;
647647
if (useField != null) {
648-
fieldType = context.fieldMapper(useField);
648+
fieldType = context.getFieldType(useField);
649649
assert fieldType != null;
650650
checkPositions(fieldType);
651651
if (this.analyzer == null) {
@@ -782,7 +782,7 @@ public IntervalsSource getSource(QueryShardContext context, MappedFieldType fiel
782782
}
783783
IntervalsSource source;
784784
if (useField != null) {
785-
fieldType = context.fieldMapper(useField);
785+
fieldType = context.getFieldType(useField);
786786
assert fieldType != null;
787787
checkPositions(fieldType);
788788
if (this.analyzer == null) {

server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
989989
}
990990
} else {
991991
for (String field : fields) {
992-
MappedFieldType fieldType = context.fieldMapper(field);
992+
MappedFieldType fieldType = context.getFieldType(field);
993993
if (fieldType != null && SUPPORTED_FIELD_TYPES.contains(fieldType.getClass()) == false) {
994994
if (failOnUnsupportedField) {
995995
throw new IllegalArgumentException("more_like_this only supports text/keyword fields: [" + field + "]");
@@ -1106,7 +1106,7 @@ private static void checkRoutingMissingException(MultiTermVectorsItemResponse re
11061106
}
11071107

11081108
private static void handleExclude(BooleanQuery.Builder boolQuery, Item[] likeItems, QueryShardContext context) {
1109-
MappedFieldType idField = context.fieldMapper(IdFieldMapper.NAME);
1109+
MappedFieldType idField = context.getFieldType(IdFieldMapper.NAME);
11101110
if (idField == null) {
11111111
// no mappings, nothing to exclude
11121112
return;

server/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
3333
import org.elasticsearch.common.xcontent.XContentBuilder;
3434
import org.elasticsearch.common.xcontent.XContentParser;
35-
import org.elasticsearch.index.mapper.MappedFieldType;
3635
import org.elasticsearch.index.mapper.ConstantFieldType;
36+
import org.elasticsearch.index.mapper.MappedFieldType;
3737
import org.elasticsearch.index.query.support.QueryParsers;
3838

3939
import java.io.IOException;
@@ -51,11 +51,11 @@ public class PrefixQueryBuilder extends AbstractQueryBuilder<PrefixQueryBuilder>
5151
private final String fieldName;
5252

5353
private final String value;
54-
54+
5555
public static final boolean DEFAULT_CASE_INSENSITIVITY = false;
5656
private static final ParseField CASE_INSENSITIVE_FIELD = new ParseField("case_insensitive");
5757
private boolean caseInsensitive = DEFAULT_CASE_INSENSITIVITY;
58-
58+
5959

6060
private String rewrite;
6161

@@ -86,7 +86,7 @@ public PrefixQueryBuilder(StreamInput in) throws IOException {
8686
rewrite = in.readOptionalString();
8787
if (in.getVersion().onOrAfter(Version.V_7_10_0)) {
8888
caseInsensitive = in.readBoolean();
89-
}
89+
}
9090
}
9191

9292
@Override
@@ -96,7 +96,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
9696
out.writeOptionalString(rewrite);
9797
if (out.getVersion().onOrAfter(Version.V_7_10_0)) {
9898
out.writeBoolean(caseInsensitive);
99-
}
99+
}
100100
}
101101

102102
@Override
@@ -107,18 +107,18 @@ public String fieldName() {
107107
public String value() {
108108
return this.value;
109109
}
110-
110+
111111
public PrefixQueryBuilder caseInsensitive(boolean caseInsensitive) {
112112
if (caseInsensitive == false) {
113113
throw new IllegalArgumentException("The case insensitive setting cannot be set to false.");
114114
}
115115
this.caseInsensitive = caseInsensitive;
116116
return this;
117-
}
117+
}
118118

119119
public boolean caseInsensitive() {
120120
return this.caseInsensitive;
121-
}
121+
}
122122

123123
public PrefixQueryBuilder rewrite(String rewrite) {
124124
this.rewrite = rewrite;
@@ -152,7 +152,7 @@ public static PrefixQueryBuilder fromXContent(XContentParser parser) throws IOEx
152152

153153
String queryName = null;
154154
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
155-
boolean caseInsensitive = DEFAULT_CASE_INSENSITIVITY;
155+
boolean caseInsensitive = DEFAULT_CASE_INSENSITIVITY;
156156
String currentFieldName = null;
157157
XContentParser.Token token;
158158
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
@@ -197,7 +197,7 @@ public static PrefixQueryBuilder fromXContent(XContentParser parser) throws IOEx
197197
.boost(boost)
198198
.queryName(queryName);
199199
if (caseInsensitive) {
200-
result.caseInsensitive(caseInsensitive);
200+
result.caseInsensitive(caseInsensitive);
201201
}
202202
return result;
203203
}
@@ -206,12 +206,12 @@ public static PrefixQueryBuilder fromXContent(XContentParser parser) throws IOEx
206206
public String getWriteableName() {
207207
return NAME;
208208
}
209-
209+
210210
@Override
211211
protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws IOException {
212212
QueryShardContext context = queryRewriteContext.convertToShardContext();
213213
if (context != null) {
214-
MappedFieldType fieldType = context.fieldMapper(this.fieldName);
214+
MappedFieldType fieldType = context.getFieldType(this.fieldName);
215215
if (fieldType == null) {
216216
return new MatchNoneQueryBuilder();
217217
} else if (fieldType instanceof ConstantFieldType) {
@@ -230,13 +230,13 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws
230230
}
231231

232232
return super.doRewrite(queryRewriteContext);
233-
}
233+
}
234234

235235
@Override
236236
protected Query doToQuery(QueryShardContext context) throws IOException {
237237
MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(rewrite, null, LoggingDeprecationHandler.INSTANCE);
238238

239-
MappedFieldType fieldType = context.fieldMapper(fieldName);
239+
MappedFieldType fieldType = context.getFieldType(fieldName);
240240
if (fieldType == null) {
241241
throw new IllegalStateException("Rewrite first");
242242
}

server/src/main/java/org/elasticsearch/index/query/QueryShardContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public Set<String> simpleMatchToIndexNames(String pattern) {
232232
* @see QueryShardContext#setAllowUnmappedFields(boolean)
233233
* @see QueryShardContext#setMapUnmappedFieldAsString(boolean)
234234
*/
235-
public MappedFieldType fieldMapper(String name) {
235+
public MappedFieldType getFieldType(String name) {
236236
return failIfFieldMappingNotFound(name, mapperService.fieldType(name));
237237
}
238238

0 commit comments

Comments
 (0)