java.lang.Object
org.elasticsearch.index.mapper.MappingLookup
A (mostly) immutable snapshot of the current mapping of an index with
access to everything we need for the search phase.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Key for the lookup to be used in caches. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MappingLookup
A lookup representing an empty mapping. -
Method Summary
Modifier and TypeMethodDescriptioncacheKey()
Key for the lookup to be used in caches.Returns an iterable over all the registered field mappers (including alias mappers)static MappingLookup
fromMappers
(Mapping mapping, Collection<FieldMapper> mappers, Collection<ObjectMapper> objectMappers) static MappingLookup
fromMappers
(Mapping mapping, Collection<FieldMapper> mappers, Collection<ObjectMapper> objectMappers, Collection<FieldAliasMapper> aliasMappers, Collection<PassThroughObjectMapper> passThroughMappers) Creates a newMappingLookup
instance given the provided mappers and mapping.static MappingLookup
fromMapping
(Mapping mapping) Creates a newMappingLookup
instance by parsing the provided mapping and extracting its field definitions.getFieldType
(String field) Returns the mapped field type for the given field name.Returns the leaf mapper associated with this field name.Returns the mapping source that this lookup originated fromgetMatchingFieldNames
(String pattern) Returns a set of field names that match a regex-like pattern All field names in the returned set are guaranteed to resolve to a fieldorg.apache.lucene.codecs.PostingsFormat
getPostingsFormat
(String field) Gets the postings format for a particular fieldlong
Returns the total number of fields defined in the mappings, including field mappers, object mappers as well as runtime fields.long
Returns the total number of mappers defined in the mappings, including field mappers and their sub-fields (which are not explicitly defined in the mappings), multi-fields, object mappers, runtime fields and metadata field mappers.boolean
Returns true if the index has mappings.boolean
Returns if this mapping contains a timestamp field that is of type date, indexed and has doc values.indexAnalyzer
(String field, Function<String, NamedAnalyzer> unmappedFieldAnalyzer) Returns a map containing all fields that require to run inference (through theInferenceService
prior to indexation.boolean
Returns if this mapping contains a data-stream's timestamp meta-field and this field is enabled.boolean
isMultiField
(String field) boolean
isObjectField
(String field) boolean
Will there be_source
.boolean
Does the source need to be rebuilt on the fly?newSourceLoader
(SourceFieldMetrics metrics) Build something to load source_source
.parentField
(String field) If field is a leaf multi-field return the path to the parent field.sourcePaths
(String field) Given a concrete field name, return its paths in the _source.void
validateDoesNotShadow
(String name) Check if the providedMappedFieldType
shadows a dimension or metric field.
-
Field Details
-
EMPTY
A lookup representing an empty mapping. It can be used to look up fields, although it won't hold any, but it does not hold a validDocumentParser
,IndexSettings
orIndexAnalyzers
.
-
-
Method Details
-
fromMapping
Creates a newMappingLookup
instance by parsing the provided mapping and extracting its field definitions.- Parameters:
mapping
- the mapping source- Returns:
- the newly created lookup instance
-
fromMappers
public static MappingLookup fromMappers(Mapping mapping, Collection<FieldMapper> mappers, Collection<ObjectMapper> objectMappers, Collection<FieldAliasMapper> aliasMappers, Collection<PassThroughObjectMapper> passThroughMappers) Creates a newMappingLookup
instance given the provided mappers and mapping. Note that the provided mappings are not re-parsed but only exposed as-is. No consistency is enforced between the provided mappings and set of mappers. This is a commodity method to be used in tests, or whenever no mappings are defined for an index. When creating a MappingLookup through this method, its exposed functionalities are limited as it does not hold a validDocumentParser
,IndexSettings
orIndexAnalyzers
.- Parameters:
mapping
- the mappingmappers
- the field mappersobjectMappers
- the object mappersaliasMappers
- the field alias mapperspassThroughMappers
- the pass-through mappers- Returns:
- the newly created lookup instance
-
fromMappers
public static MappingLookup fromMappers(Mapping mapping, Collection<FieldMapper> mappers, Collection<ObjectMapper> objectMappers) -
getMapper
Returns the leaf mapper associated with this field name. Note that the returned mapper could be either a concreteFieldMapper
, or aFieldAliasMapper
. To access a field's type information,MapperService.fieldType(java.lang.String)
should be used instead. -
getTotalFieldsCount
public long getTotalFieldsCount()Returns the total number of fields defined in the mappings, including field mappers, object mappers as well as runtime fields. -
getTotalMapperCount
public long getTotalMapperCount()Returns the total number of mappers defined in the mappings, including field mappers and their sub-fields (which are not explicitly defined in the mappings), multi-fields, object mappers, runtime fields and metadata field mappers. -
indexAnalyzer
public NamedAnalyzer indexAnalyzer(String field, Function<String, NamedAnalyzer> unmappedFieldAnalyzer) -
fieldMappers
Returns an iterable over all the registered field mappers (including alias mappers) -
getPostingsFormat
Gets the postings format for a particular field- Parameters:
field
- the field to retrieve a postings format for- Returns:
- the postings format for the field, or
null
if the default format should be used
-
objectMappers
-
inferenceFields
Returns a map containing all fields that require to run inference (through theInferenceService
prior to indexation. -
nestedLookup
-
isMultiField
-
isObjectField
-
getMatchingFieldNames
Returns a set of field names that match a regex-like pattern All field names in the returned set are guaranteed to resolve to a field- Parameters:
pattern
- the pattern to match field names against
-
getFullNameToFieldType
- Returns:
- A map from field name to the MappedFieldType
-
getFieldType
Returns the mapped field type for the given field name. -
sourcePaths
Given a concrete field name, return its paths in the _source. For most fields, the source path is the same as the field itself. However there are cases where a field's values are found elsewhere in the _source: - For a multi-field, the source path is the parent field. - One field's content could have been copied to another through copy_to.- Parameters:
field
- The field for which to look up the _source path. Note that the field should be a concrete field and *not* an alias.- Returns:
- A set of paths in the _source that contain the field's values.
-
parentField
If field is a leaf multi-field return the path to the parent field. Otherwise, return null. -
hasMappings
public boolean hasMappings()Returns true if the index has mappings. An index does not have mappings only if it was created without providing mappings explicitly, and no documents have yet been indexed in it.- Returns:
- true if the current index has mappings, false otherwise
-
isSourceEnabled
public boolean isSourceEnabled()Will there be_source
. -
isSourceSynthetic
public boolean isSourceSynthetic()Does the source need to be rebuilt on the fly? -
newSourceLoader
Build something to load source_source
. -
isDataStreamTimestampFieldEnabled
public boolean isDataStreamTimestampFieldEnabled()Returns if this mapping contains a data-stream's timestamp meta-field and this field is enabled. Only indices that are a part of a data-stream have this meta-field enabled.- Returns:
true
if contains an enabled data-stream's timestamp meta-field,false
otherwise.
-
hasTimestampField
public boolean hasTimestampField()Returns if this mapping contains a timestamp field that is of type date, indexed and has doc values.- Returns:
true
if contains a timestamp field of type date that is indexed and has doc values,false
otherwise.
-
cacheKey
Key for the lookup to be used in caches. -
getMapping
Returns the mapping source that this lookup originated from- Returns:
- the mapping source
-
validateDoesNotShadow
Check if the providedMappedFieldType
shadows a dimension or metric field.
-