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.
This commit is contained in:
parent
12fa0f437a
commit
00b0e10063
|
@ -76,7 +76,7 @@ public class TransportFieldCapabilitiesIndexAction extends TransportSingleShardA
|
||||||
MapperService mapperService = indicesService.indexServiceSafe(shardId.getIndex()).mapperService();
|
MapperService mapperService = indicesService.indexServiceSafe(shardId.getIndex()).mapperService();
|
||||||
Set<String> fieldNames = new HashSet<>();
|
Set<String> fieldNames = new HashSet<>();
|
||||||
for (String field : request.fields()) {
|
for (String field : request.fields()) {
|
||||||
fieldNames.addAll(mapperService.simpleMatchToIndexNames(field));
|
fieldNames.addAll(mapperService.simpleMatchToFullName(field));
|
||||||
}
|
}
|
||||||
Predicate<String> fieldPredicate = indicesService.getFieldFilter().apply(shardId.getIndexName());
|
Predicate<String> fieldPredicate = indicesService.getFieldFilter().apply(shardId.getIndexName());
|
||||||
Map<String, FieldCapabilities> responseMap = new HashMap<>();
|
Map<String, FieldCapabilities> responseMap = new HashMap<>();
|
||||||
|
|
|
@ -20,16 +20,13 @@
|
||||||
package org.elasticsearch.index.mapper;
|
package org.elasticsearch.index.mapper;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.elasticsearch.common.regex.Regex;
|
|
||||||
import org.elasticsearch.index.analysis.FieldNameAnalyzer;
|
import org.elasticsearch.index.analysis.FieldNameAnalyzer;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public final class DocumentFieldMappers implements Iterable<FieldMapper> {
|
public final class DocumentFieldMappers implements Iterable<FieldMapper> {
|
||||||
|
|
||||||
|
@ -70,16 +67,6 @@ public final class DocumentFieldMappers implements Iterable<FieldMapper> {
|
||||||
return fieldMappers.get(field);
|
return fieldMappers.get(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<String> simpleMatchToFullName(String pattern) {
|
|
||||||
Set<String> fields = new HashSet<>();
|
|
||||||
for (FieldMapper fieldMapper : this) {
|
|
||||||
if (Regex.simpleMatch(pattern, fieldMapper.fieldType().name())) {
|
|
||||||
fields.add(fieldMapper.fieldType().name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A smart analyzer used for indexing that takes into account specific analyzers configured
|
* A smart analyzer used for indexing that takes into account specific analyzers configured
|
||||||
* per {@link FieldMapper}.
|
* per {@link FieldMapper}.
|
||||||
|
|
|
@ -721,7 +721,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
|
||||||
* Returns all the fields that match the given pattern. If the pattern is prefixed with a type
|
* Returns all the fields that match the given pattern. If the pattern is prefixed with a type
|
||||||
* then the fields will be returned with a type prefix.
|
* then the fields will be returned with a type prefix.
|
||||||
*/
|
*/
|
||||||
public Collection<String> simpleMatchToIndexNames(String pattern) {
|
public Collection<String> simpleMatchToFullName(String pattern) {
|
||||||
if (Regex.isSimpleMatchPattern(pattern) == false) {
|
if (Regex.isSimpleMatchPattern(pattern) == false) {
|
||||||
// no wildcards
|
// no wildcards
|
||||||
return Collections.singletonList(pattern);
|
return Collections.singletonList(pattern);
|
||||||
|
|
|
@ -198,7 +198,7 @@ public class QueryShardContext extends QueryRewriteContext {
|
||||||
* type then the fields will be returned with a type prefix.
|
* type then the fields will be returned with a type prefix.
|
||||||
*/
|
*/
|
||||||
public Collection<String> simpleMatchToIndexNames(String pattern) {
|
public Collection<String> simpleMatchToIndexNames(String pattern) {
|
||||||
return mapperService.simpleMatchToIndexNames(pattern);
|
return mapperService.simpleMatchToFullName(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MappedFieldType fieldMapper(String name) {
|
public MappedFieldType fieldMapper(String name) {
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class TermVectorsService {
|
||||||
private static void handleFieldWildcards(IndexShard indexShard, TermVectorsRequest request) {
|
private static void handleFieldWildcards(IndexShard indexShard, TermVectorsRequest request) {
|
||||||
Set<String> fieldNames = new HashSet<>();
|
Set<String> fieldNames = new HashSet<>();
|
||||||
for (String pattern : request.selectedFields()) {
|
for (String pattern : request.selectedFields()) {
|
||||||
fieldNames.addAll(indexShard.mapperService().simpleMatchToIndexNames(pattern));
|
fieldNames.addAll(indexShard.mapperService().simpleMatchToFullName(pattern));
|
||||||
}
|
}
|
||||||
request.selectedFields(fieldNames.toArray(Strings.EMPTY_ARRAY));
|
request.selectedFields(fieldNames.toArray(Strings.EMPTY_ARRAY));
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,7 @@ public class HighlightPhase extends AbstractComponent implements FetchSubPhase {
|
||||||
for (SearchContextHighlight.Field field : context.highlight().fields()) {
|
for (SearchContextHighlight.Field field : context.highlight().fields()) {
|
||||||
Collection<String> fieldNamesToHighlight;
|
Collection<String> fieldNamesToHighlight;
|
||||||
if (Regex.isSimpleMatchPattern(field.field())) {
|
if (Regex.isSimpleMatchPattern(field.field())) {
|
||||||
DocumentMapper documentMapper = context.mapperService().documentMapper(hitContext.hit().getType());
|
fieldNamesToHighlight = context.mapperService().simpleMatchToFullName(field.field());
|
||||||
fieldNamesToHighlight = documentMapper.mappers().simpleMatchToFullName(field.field());
|
|
||||||
} else {
|
} else {
|
||||||
fieldNamesToHighlight = Collections.singletonList(field.field());
|
fieldNamesToHighlight = Collections.singletonList(field.field());
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class FieldNamesFieldTypeTests extends FieldTypeTestCase {
|
||||||
MapperService mapperService = mock(MapperService.class);
|
MapperService mapperService = mock(MapperService.class);
|
||||||
when(mapperService.fullName("_field_names")).thenReturn(fieldNamesFieldType);
|
when(mapperService.fullName("_field_names")).thenReturn(fieldNamesFieldType);
|
||||||
when(mapperService.fullName("field_name")).thenReturn(fieldType);
|
when(mapperService.fullName("field_name")).thenReturn(fieldType);
|
||||||
when(mapperService.simpleMatchToIndexNames("field_name")).thenReturn(Collections.singletonList("field_name"));
|
when(mapperService.simpleMatchToFullName("field_name")).thenReturn(Collections.singletonList("field_name"));
|
||||||
|
|
||||||
QueryShardContext queryShardContext = new QueryShardContext(0,
|
QueryShardContext queryShardContext = new QueryShardContext(0,
|
||||||
indexSettings, null, null, mapperService, null, null, null, null, null, null, () -> 0L, null);
|
indexSettings, null, null, mapperService, null, null, null, null, null, null, () -> 0L, null);
|
||||||
|
|
|
@ -126,7 +126,8 @@ import org.elasticsearch.index.MergeSchedulerConfig;
|
||||||
import org.elasticsearch.index.MockEngineFactoryPlugin;
|
import org.elasticsearch.index.MockEngineFactoryPlugin;
|
||||||
import org.elasticsearch.index.codec.CodecService;
|
import org.elasticsearch.index.codec.CodecService;
|
||||||
import org.elasticsearch.index.engine.Segment;
|
import org.elasticsearch.index.engine.Segment;
|
||||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
import org.elasticsearch.index.mapper.MockFieldFilterPlugin;
|
import org.elasticsearch.index.mapper.MockFieldFilterPlugin;
|
||||||
import org.elasticsearch.index.seqno.SeqNoStats;
|
import org.elasticsearch.index.seqno.SeqNoStats;
|
||||||
import org.elasticsearch.index.seqno.SequenceNumbers;
|
import org.elasticsearch.index.seqno.SequenceNumbers;
|
||||||
|
@ -823,7 +824,7 @@ public abstract class ESIntegTestCase extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits till a (pattern) field name mappings concretely exists on all nodes. Note, this waits for the current
|
* Waits until mappings for the provided fields exist on all nodes. Note, this waits for the current
|
||||||
* started shards and checks for concrete mappings.
|
* started shards and checks for concrete mappings.
|
||||||
*/
|
*/
|
||||||
public void assertConcreteMappingsOnAll(final String index, final String type, final String... fieldNames) throws Exception {
|
public void assertConcreteMappingsOnAll(final String index, final String type, final String... fieldNames) throws Exception {
|
||||||
|
@ -833,11 +834,10 @@ public abstract class ESIntegTestCase extends ESTestCase {
|
||||||
IndicesService indicesService = internalCluster().getInstance(IndicesService.class, node);
|
IndicesService indicesService = internalCluster().getInstance(IndicesService.class, node);
|
||||||
IndexService indexService = indicesService.indexService(resolveIndex(index));
|
IndexService indexService = indicesService.indexService(resolveIndex(index));
|
||||||
assertThat("index service doesn't exists on " + node, indexService, notNullValue());
|
assertThat("index service doesn't exists on " + node, indexService, notNullValue());
|
||||||
DocumentMapper documentMapper = indexService.mapperService().documentMapper(type);
|
MapperService mapperService = indexService.mapperService();
|
||||||
assertThat("document mapper doesn't exists on " + node, documentMapper, notNullValue());
|
|
||||||
for (String fieldName : fieldNames) {
|
for (String fieldName : fieldNames) {
|
||||||
Collection<String> matches = documentMapper.mappers().simpleMatchToFullName(fieldName);
|
MappedFieldType fieldType = mapperService.fullName(fieldName);
|
||||||
assertThat("field " + fieldName + " doesn't exists on " + node, matches, Matchers.not(emptyIterable()));
|
assertNotNull("field " + fieldName + " doesn't exists on " + node, fieldType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertMappingOnMaster(index, type, fieldNames);
|
assertMappingOnMaster(index, type, fieldNames);
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class SecurityIndexSearcherWrapperIntegrationTests extends ESTestCase {
|
||||||
MapperService mapperService = mock(MapperService.class);
|
MapperService mapperService = mock(MapperService.class);
|
||||||
ScriptService scriptService = mock(ScriptService.class);
|
ScriptService scriptService = mock(ScriptService.class);
|
||||||
when(mapperService.documentMapper()).thenReturn(null);
|
when(mapperService.documentMapper()).thenReturn(null);
|
||||||
when(mapperService.simpleMatchToIndexNames(anyString()))
|
when(mapperService.simpleMatchToFullName(anyString()))
|
||||||
.then(invocationOnMock -> Collections.singletonList((String) invocationOnMock.getArguments()[0]));
|
.then(invocationOnMock -> Collections.singletonList((String) invocationOnMock.getArguments()[0]));
|
||||||
|
|
||||||
ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
|
ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
|
||||||
|
|
Loading…
Reference in New Issue