Class FieldMapper

java.lang.Object
org.elasticsearch.index.mapper.Mapper
org.elasticsearch.index.mapper.FieldMapper
All Implemented Interfaces:
Iterable<Mapper>, ToXContent, ToXContentFragment
Direct Known Subclasses:
AbstractGeometryFieldMapper, BinaryFieldMapper, BooleanFieldMapper, CompletionFieldMapper, DateFieldMapper, DenseVectorFieldMapper, FlattenedFieldMapper, IpFieldMapper, KeywordFieldMapper, MetadataFieldMapper, NumberFieldMapper, PlaceHolderFieldMapper, RangeFieldMapper, SparseVectorFieldMapper, TextFieldMapper

public abstract class FieldMapper extends Mapper
  • Field Details

  • Constructor Details

    • FieldMapper

      protected FieldMapper(String simpleName, MappedFieldType mappedFieldType, FieldMapper.BuilderParams params)
      Parameters:
      simpleName - the leaf name of the mapper
      params - initialization params for this field mapper
  • Method Details

    • fullPath

      public String fullPath()
      Description copied from class: Mapper
      Returns the canonical name which uniquely identifies the mapper against other mappers in a type.
      Specified by:
      fullPath in class Mapper
    • typeName

      public String typeName()
      Description copied from class: Mapper
      Returns a name representing the type of this mapper.
      Specified by:
      typeName in class Mapper
    • fieldType

      public MappedFieldType fieldType()
    • copyTo

      public FieldMapper.CopyTo copyTo()
      List of fields where this field should be copied to
    • multiFields

      public FieldMapper.MultiFields multiFields()
    • sourceKeepMode

      public Optional<Mapper.SourceKeepMode> sourceKeepMode()
    • ignoreMalformed

      public boolean ignoreMalformed()
      Will this field ignore malformed values for this field and accept the document (true) or will it reject documents with malformed values for this field (false). Some fields don't have a concept of "malformed" and will return false here.
    • parsesArrayValue

      public boolean parsesArrayValue()
      Whether this mapper can handle an array value during document parsing. If true, when an array is encountered during parsing, the document parser will pass the whole array to the mapper. If false, the array is split into individual values and each value is passed to the mapper for parsing.
    • supportsParsingObject

      protected boolean supportsParsingObject()
      Whether this mapper can handle an object value during document parsing. When the subobjects property is set to false, and we encounter an object while parsing we need a way to understand if its fieldMapper is able to parse an object. If that's the case we can provide the entire object to the FieldMapper otherwise its name becomes the part of the dotted field name of each internal value.
    • parse

      public void parse(DocumentParserContext context) throws IOException
      Parse the field value using the provided DocumentParserContext.
      Throws:
      IOException
    • parseCreateField

      protected abstract void parseCreateField(DocumentParserContext context) throws IOException
      Parse the field value and populate the fields on DocumentParserContext.doc(). Implementations of this method should ensure that on failing to parse parser.currentToken() must be the current failing token
      Throws:
      IOException
    • hasScript

      public final boolean hasScript()
      Returns:
      whether this field mapper uses a script to generate its values
    • executeScript

      public final void executeScript(SearchLookup searchLookup, org.apache.lucene.index.LeafReaderContext readerContext, int doc, DocumentParserContext documentParserContext)
      Execute the index-time script associated with this field mapper. This method should only be called if hasScript() has returned true
      Parameters:
      searchLookup - a SearchLookup to be passed the script
      readerContext - a LeafReaderContext exposing values from an incoming document
      doc - the id of the document to execute the script against
      documentParserContext - the ParseContext over the incoming document
    • indexScriptValues

      protected void indexScriptValues(SearchLookup searchLookup, org.apache.lucene.index.LeafReaderContext readerContext, int doc, DocumentParserContext documentParserContext)
      Run the script associated with the field and index the values that it emits This method should only be called if hasScript() has returned true
      Parameters:
      searchLookup - a SearchLookup to be passed the script
      readerContext - a LeafReaderContext exposing values from an incoming document
      doc - the id of the document to execute the script against
      documentParserContext - the ParseContext over the incoming document
    • iterator

      public Iterator<Mapper> iterator()
    • multiFieldsIterator

      protected Iterator<Mapper> multiFieldsIterator()
    • sourcePathUsedBy

      public Iterator<Mapper> sourcePathUsedBy()
      Returns:
      a mapper iterator of all fields that use this field's source path as their source path
    • validate

      public final void validate(MappingLookup mappers)
      Description copied from class: Mapper
      Validate any cross-field references made by this mapper
      Specified by:
      validate in class Mapper
      Parameters:
      mappers - a MappingLookup that can produce references to other mappers
    • doValidate

      protected void doValidate(MappingLookup mappers)
    • getMergeBuilder

      public abstract FieldMapper.Builder getMergeBuilder()
      Returns a FieldMapper.Builder to be used for merging and serialization Implement as follows: return new MyBuilder(simpleName()).init(this);
    • merge

      public final FieldMapper merge(Mapper mergeWith, MapperMergeContext mapperMergeContext)
      Description copied from class: Mapper
      Return the merge of mergeWith into this. Both this and mergeWith will be left unmodified.
      Specified by:
      merge in class Mapper
    • checkIncomingMergeType

      protected void checkIncomingMergeType(FieldMapper mergeWith)
    • toXContent

      public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException
      Throws:
      IOException
    • doXContentBody

      protected void doXContentBody(XContentBuilder builder, ToXContent.Params params) throws IOException
      Throws:
      IOException
    • contentType

      protected abstract String contentType()
    • getTotalFieldsCount

      public int getTotalFieldsCount()
      Description copied from class: Mapper
      The total number of fields as defined in the mapping. Defines how this mapper counts towards MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.
      Specified by:
      getTotalFieldsCount in class Mapper
    • indexAnalyzers

      public Map<String,NamedAnalyzer> indexAnalyzers()
    • syntheticFieldLoader

      public final SourceLoader.SyntheticFieldLoader syntheticFieldLoader()
      Returns synthetic field loader for the mapper. If mapper does not support synthetic source, it is handled using generic implementation in DocumentParser.parseObjectOrField(org.elasticsearch.index.mapper.DocumentParserContext, org.elasticsearch.index.mapper.Mapper) and ObjectMapper.syntheticFieldLoader(SourceFilter).
      This method is final in order to support common use cases like fallback synthetic source. Mappers that need custom support of synthetic source should override syntheticSourceSupport().
      Returns:
      implementation of SourceLoader.SyntheticFieldLoader
    • syntheticSourceSupport

      protected FieldMapper.SyntheticSourceSupport syntheticSourceSupport()

      Returns implementation of synthetic source support for the mapper.
      By default (meaning FieldMapper.SyntheticSourceSupport.Fallback), an exact full copy of parsed field value is stored separately and used for synthetic source.

      Field mappers must override this method if they provide a more efficient field-specific implementation of synthetic source.

      Returns:
      FieldMapper.SyntheticSourceMode
    • notInMultiFields

      public static BiConsumer<String,MappingParserContext> notInMultiFields(String type)
    • notFromDynamicTemplates

      public static BiConsumer<String,MappingParserContext> notFromDynamicTemplates(String type)
    • createTypeParserWithLegacySupport

      public static FieldMapper.TypeParser createTypeParserWithLegacySupport(BiFunction<String,MappingParserContext,FieldMapper.Builder> builderFunction)