Class FieldMapper

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

public abstract class FieldMapper extends Mapper implements Cloneable
  • Field Details

  • Constructor Details

    • FieldMapper

      protected FieldMapper(String simpleName, MappedFieldType mappedFieldType, FieldMapper.MultiFields multiFields, FieldMapper.CopyTo copyTo)
      Create a FieldMapper with no index analyzers
      Parameters:
      simpleName - the leaf name of the mapper
      mappedFieldType - the MappedFieldType associated with this mapper
      multiFields - sub fields of this mapper
      copyTo - copyTo fields of this mapper
    • FieldMapper

      protected FieldMapper(String simpleName, MappedFieldType mappedFieldType, FieldMapper.MultiFields multiFields, FieldMapper.CopyTo copyTo, boolean hasScript, String onScriptError)
      Create a FieldMapper with no index analyzers
      Parameters:
      simpleName - the leaf name of the mapper
      mappedFieldType - the MappedFieldType associated with this mapper
      multiFields - sub fields of this mapper
      copyTo - copyTo fields of this mapper
      hasScript - whether a script is defined for the field
      onScriptError - the behaviour for when the defined script fails at runtime
    • FieldMapper

      protected FieldMapper(String simpleName, MappedFieldType mappedFieldType, NamedAnalyzer indexAnalyzer, FieldMapper.MultiFields multiFields, FieldMapper.CopyTo copyTo)
      Create a FieldMapper with a single associated index analyzer
      Parameters:
      simpleName - the leaf name of the mapper
      mappedFieldType - the MappedFieldType associated with this mapper
      indexAnalyzer - the index-time analyzer to use for this field
      multiFields - sub fields of this mapper
      copyTo - copyTo fields of this mapper
    • FieldMapper

      protected FieldMapper(String simpleName, MappedFieldType mappedFieldType, NamedAnalyzer indexAnalyzer, FieldMapper.MultiFields multiFields, FieldMapper.CopyTo copyTo, boolean hasScript, String onScriptError)
      Create a FieldMapper with a single associated index analyzer
      Parameters:
      simpleName - the leaf name of the mapper
      mappedFieldType - the MappedFieldType associated with this mapper
      indexAnalyzer - the index-time analyzer to use for this field
      multiFields - sub fields of this mapper
      copyTo - copyTo fields of this mapper
      hasScript - whether a script is defined for the field
      onScriptError - the behaviour for when the defined script fails at runtime
    • FieldMapper

      protected FieldMapper(String simpleName, MappedFieldType mappedFieldType, Map<String,NamedAnalyzer> indexAnalyzers, FieldMapper.MultiFields multiFields, FieldMapper.CopyTo copyTo, boolean hasScript, String onScriptError)
      Create a FieldMapper that indexes into multiple analyzed fields
      Parameters:
      simpleName - the leaf name of the mapper
      mappedFieldType - the MappedFieldType associated with this mapper
      indexAnalyzers - a map of field names to analyzers, one for each analyzed field the mapper will add
      multiFields - sub fields of this mapper
      copyTo - copyTo fields of this mapper
      hasScript - whether a script is defined for the field
      onScriptError - the behaviour for when the defined script fails at runtime
  • Method Details

    • name

      public String name()
      Description copied from class: Mapper
      Returns the canonical name which uniquely identifies the mapper against other mappers in a type.
      Specified by:
      name 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()
    • 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.
    • 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()
      Specified by:
      iterator in interface Iterable<Mapper>
    • 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)
      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 org.elasticsearch.xcontent.XContentBuilder toXContent(org.elasticsearch.xcontent.XContentBuilder builder, org.elasticsearch.xcontent.ToXContent.Params params) throws IOException
      Specified by:
      toXContent in interface org.elasticsearch.xcontent.ToXContent
      Throws:
      IOException
    • doXContentBody

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

      protected abstract String contentType()
    • indexAnalyzers

      public final Map<String,NamedAnalyzer> indexAnalyzers()
    • notInMultiFields

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