Skip to content

Commit 00b0e10

Browse files
authored
Remove DocumentFieldMappers#simpleMatchToFullName. (#31041)
* Remove DocumentFieldMappers#simpleMatchToFullName, as it is duplicative of MapperService#simpleMatchToIndexNames. * Rename MapperService#simpleMatchToIndexNames -> simpleMatchToFullName for consistency. * Simplify EsIntegTestCase#assertConcreteMappingsOnAll to accept concrete fields instead of wildcard patterns.
1 parent 12fa0f4 commit 00b0e10

File tree

9 files changed

+13
-27
lines changed

9 files changed

+13
-27
lines changed

server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesIndexAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected FieldCapabilitiesIndexResponse shardOperation(final FieldCapabilitiesI
7676
MapperService mapperService = indicesService.indexServiceSafe(shardId.getIndex()).mapperService();
7777
Set<String> fieldNames = new HashSet<>();
7878
for (String field : request.fields()) {
79-
fieldNames.addAll(mapperService.simpleMatchToIndexNames(field));
79+
fieldNames.addAll(mapperService.simpleMatchToFullName(field));
8080
}
8181
Predicate<String> fieldPredicate = indicesService.getFieldFilter().apply(shardId.getIndexName());
8282
Map<String, FieldCapabilities> responseMap = new HashMap<>();

server/src/main/java/org/elasticsearch/index/mapper/DocumentFieldMappers.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@
2020
package org.elasticsearch.index.mapper;
2121

2222
import org.apache.lucene.analysis.Analyzer;
23-
import org.elasticsearch.common.regex.Regex;
2423
import org.elasticsearch.index.analysis.FieldNameAnalyzer;
2524

2625
import java.util.Collection;
2726
import java.util.Collections;
2827
import java.util.HashMap;
29-
import java.util.HashSet;
3028
import java.util.Iterator;
3129
import java.util.Map;
32-
import java.util.Set;
3330

3431
public final class DocumentFieldMappers implements Iterable<FieldMapper> {
3532

@@ -70,16 +67,6 @@ public FieldMapper getMapper(String field) {
7067
return fieldMappers.get(field);
7168
}
7269

73-
public Collection<String> simpleMatchToFullName(String pattern) {
74-
Set<String> fields = new HashSet<>();
75-
for (FieldMapper fieldMapper : this) {
76-
if (Regex.simpleMatch(pattern, fieldMapper.fieldType().name())) {
77-
fields.add(fieldMapper.fieldType().name());
78-
}
79-
}
80-
return fields;
81-
}
82-
8370
/**
8471
* A smart analyzer used for indexing that takes into account specific analyzers configured
8572
* per {@link FieldMapper}.

server/src/main/java/org/elasticsearch/index/mapper/MapperService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ public MappedFieldType fullName(String fullName) {
721721
* Returns all the fields that match the given pattern. If the pattern is prefixed with a type
722722
* then the fields will be returned with a type prefix.
723723
*/
724-
public Collection<String> simpleMatchToIndexNames(String pattern) {
724+
public Collection<String> simpleMatchToFullName(String pattern) {
725725
if (Regex.isSimpleMatchPattern(pattern) == false) {
726726
// no wildcards
727727
return Collections.singletonList(pattern);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public void setIsFilter(boolean isFilter) {
198198
* type then the fields will be returned with a type prefix.
199199
*/
200200
public Collection<String> simpleMatchToIndexNames(String pattern) {
201-
return mapperService.simpleMatchToIndexNames(pattern);
201+
return mapperService.simpleMatchToFullName(pattern);
202202
}
203203

204204
public MappedFieldType fieldMapper(String name) {

server/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ else if (docIdAndVersion != null) {
155155
private static void handleFieldWildcards(IndexShard indexShard, TermVectorsRequest request) {
156156
Set<String> fieldNames = new HashSet<>();
157157
for (String pattern : request.selectedFields()) {
158-
fieldNames.addAll(indexShard.mapperService().simpleMatchToIndexNames(pattern));
158+
fieldNames.addAll(indexShard.mapperService().simpleMatchToFullName(pattern));
159159
}
160160
request.selectedFields(fieldNames.toArray(Strings.EMPTY_ARRAY));
161161
}

server/src/main/java/org/elasticsearch/search/fetch/subphase/highlight/HighlightPhase.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public void hitExecute(SearchContext context, HitContext hitContext) {
5353
for (SearchContextHighlight.Field field : context.highlight().fields()) {
5454
Collection<String> fieldNamesToHighlight;
5555
if (Regex.isSimpleMatchPattern(field.field())) {
56-
DocumentMapper documentMapper = context.mapperService().documentMapper(hitContext.hit().getType());
57-
fieldNamesToHighlight = documentMapper.mappers().simpleMatchToFullName(field.field());
56+
fieldNamesToHighlight = context.mapperService().simpleMatchToFullName(field.field());
5857
} else {
5958
fieldNamesToHighlight = Collections.singletonList(field.field());
6059
}

server/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldTypeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void testTermQuery() {
6363
MapperService mapperService = mock(MapperService.class);
6464
when(mapperService.fullName("_field_names")).thenReturn(fieldNamesFieldType);
6565
when(mapperService.fullName("field_name")).thenReturn(fieldType);
66-
when(mapperService.simpleMatchToIndexNames("field_name")).thenReturn(Collections.singletonList("field_name"));
66+
when(mapperService.simpleMatchToFullName("field_name")).thenReturn(Collections.singletonList("field_name"));
6767

6868
QueryShardContext queryShardContext = new QueryShardContext(0,
6969
indexSettings, null, null, mapperService, null, null, null, null, null, null, () -> 0L, null);

test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@
126126
import org.elasticsearch.index.MockEngineFactoryPlugin;
127127
import org.elasticsearch.index.codec.CodecService;
128128
import org.elasticsearch.index.engine.Segment;
129-
import org.elasticsearch.index.mapper.DocumentMapper;
129+
import org.elasticsearch.index.mapper.MappedFieldType;
130+
import org.elasticsearch.index.mapper.MapperService;
130131
import org.elasticsearch.index.mapper.MockFieldFilterPlugin;
131132
import org.elasticsearch.index.seqno.SeqNoStats;
132133
import org.elasticsearch.index.seqno.SequenceNumbers;
@@ -823,7 +824,7 @@ public void waitNoPendingTasksOnAll() throws Exception {
823824
}
824825

825826
/**
826-
* Waits till a (pattern) field name mappings concretely exists on all nodes. Note, this waits for the current
827+
* Waits until mappings for the provided fields exist on all nodes. Note, this waits for the current
827828
* started shards and checks for concrete mappings.
828829
*/
829830
public void assertConcreteMappingsOnAll(final String index, final String type, final String... fieldNames) throws Exception {
@@ -833,11 +834,10 @@ public void assertConcreteMappingsOnAll(final String index, final String type, f
833834
IndicesService indicesService = internalCluster().getInstance(IndicesService.class, node);
834835
IndexService indexService = indicesService.indexService(resolveIndex(index));
835836
assertThat("index service doesn't exists on " + node, indexService, notNullValue());
836-
DocumentMapper documentMapper = indexService.mapperService().documentMapper(type);
837-
assertThat("document mapper doesn't exists on " + node, documentMapper, notNullValue());
837+
MapperService mapperService = indexService.mapperService();
838838
for (String fieldName : fieldNames) {
839-
Collection<String> matches = documentMapper.mappers().simpleMatchToFullName(fieldName);
840-
assertThat("field " + fieldName + " doesn't exists on " + node, matches, Matchers.not(emptyIterable()));
839+
MappedFieldType fieldType = mapperService.fullName(fieldName);
840+
assertNotNull("field " + fieldName + " doesn't exists on " + node, fieldType);
841841
}
842842
}
843843
assertMappingOnMaster(index, type, fieldNames);

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/SecurityIndexSearcherWrapperIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void testDLS() throws Exception {
5959
MapperService mapperService = mock(MapperService.class);
6060
ScriptService scriptService = mock(ScriptService.class);
6161
when(mapperService.documentMapper()).thenReturn(null);
62-
when(mapperService.simpleMatchToIndexNames(anyString()))
62+
when(mapperService.simpleMatchToFullName(anyString()))
6363
.then(invocationOnMock -> Collections.singletonList((String) invocationOnMock.getArguments()[0]));
6464

6565
ThreadContext threadContext = new ThreadContext(Settings.EMPTY);

0 commit comments

Comments
 (0)