Skip to content

Commit 49ea435

Browse files
committed
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. (cherry picked from commit 00b0e10)
1 parent 28011ef commit 49ea435

File tree

10 files changed

+14
-28
lines changed

10 files changed

+14
-28
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
@@ -789,7 +789,7 @@ public MappedFieldType fullName(String fullName) {
789789
* Returns all the fields that match the given pattern. If the pattern is prefixed with a type
790790
* then the fields will be returned with a type prefix.
791791
*/
792-
public Collection<String> simpleMatchToIndexNames(String pattern) {
792+
public Collection<String> simpleMatchToFullName(String pattern) {
793793
if (Regex.isSimpleMatchPattern(pattern) == false) {
794794
// no wildcards
795795
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
@@ -197,7 +197,7 @@ public void setIsFilter(boolean isFilter) {
197197
* type then the fields will be returned with a type prefix.
198198
*/
199199
public Collection<String> simpleMatchToIndexNames(String pattern) {
200-
return mapperService.simpleMatchToIndexNames(pattern);
200+
return mapperService.simpleMatchToFullName(pattern);
201201
}
202202

203203
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
@@ -158,7 +158,7 @@ else if (docIdAndVersion != null) {
158158
private static void handleFieldWildcards(IndexShard indexShard, TermVectorsRequest request) {
159159
Set<String> fieldNames = new HashSet<>();
160160
for (String pattern : request.selectedFields()) {
161-
fieldNames.addAll(indexShard.mapperService().simpleMatchToIndexNames(pattern));
161+
fieldNames.addAll(indexShard.mapperService().simpleMatchToFullName(pattern));
162162
}
163163
request.selectedFields(fieldNames.toArray(Strings.EMPTY_ARRAY));
164164
}

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);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void testNoParentNullFieldCreatedIfNoParentSpecified() throws Exception {
124124
.endObject()
125125
.endObject().endObject();
126126
mapperService.merge("some_type", new CompressedXContent(Strings.toString(mappingSource)), MergeReason.MAPPING_UPDATE, false);
127-
Set<String> allFields = new HashSet<>(mapperService.simpleMatchToIndexNames("*"));
127+
Set<String> allFields = new HashSet<>(mapperService.simpleMatchToFullName("*"));
128128
assertTrue(allFields.contains("_parent"));
129129
assertFalse(allFields.contains("_parent#null"));
130130
MappedFieldType fieldType = mapperService.fullName("_parent");

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
@@ -60,7 +60,7 @@ public void testDLS() throws Exception {
6060
MapperService mapperService = mock(MapperService.class);
6161
ScriptService scriptService = mock(ScriptService.class);
6262
when(mapperService.docMappers(anyBoolean())).thenReturn(Collections.emptyList());
63-
when(mapperService.simpleMatchToIndexNames(anyString()))
63+
when(mapperService.simpleMatchToFullName(anyString()))
6464
.then(invocationOnMock -> Collections.singletonList((String) invocationOnMock.getArguments()[0]));
6565

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

0 commit comments

Comments
 (0)