Class MappedFieldType

java.lang.Object
org.elasticsearch.index.mapper.MappedFieldType
Direct Known Subclasses:
AbstractGeometryFieldMapper.AbstractGeometryFieldType, BinaryFieldMapper.BinaryFieldType, ConstantFieldType, DateFieldMapper.DateFieldType, RangeFieldMapper.RangeFieldType, SimpleMappedFieldType

public abstract class MappedFieldType
extends java.lang.Object
This defines the core properties and functions to operate on a field.
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  MappedFieldType.Relation
    An enum used to describe the relation between the range of terms in a shard when compared with a query range
  • Constructor Summary

    Constructors 
    Constructor Description
    MappedFieldType​(java.lang.String name, boolean isIndexed, boolean hasDocValues, TextSearchInfo textSearchInfo, java.util.Map<java.lang.String,​java.lang.String> meta)  
  • Method Summary

    Modifier and Type Method Description
    float boost()  
    DocValueFormat docValueFormat​(java.lang.String format, java.time.ZoneId timeZone)
    Return a DocValueFormat that can be used to display and parse values as returned by the fielddata API.
    boolean eagerGlobalOrdinals()  
    abstract org.apache.lucene.search.Query existsQuery​(QueryShardContext context)  
    static org.apache.lucene.index.Term extractTerm​(org.apache.lucene.search.Query termQuery)
    Extract a Term from a query created with termQuery(java.lang.Object, org.elasticsearch.index.query.QueryShardContext) by recursively removing BoostQuery wrappers.
    protected void failIfNoDocValues()  
    protected void failIfNotIndexed()  
    java.lang.String familyTypeName()
    Returns the field family type, as used in field capabilities
    IndexFieldData.Builder fielddataBuilder​(java.lang.String fullyQualifiedIndexName)
    Return a fielddata builder for this field
    org.apache.lucene.search.Query fuzzyQuery​(java.lang.Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions, QueryShardContext context)  
    TextSearchInfo getTextSearchInfo()
    Returns information on how any text in this field is indexed Fields that do not support any text-based queries should return TextSearchInfo.NONE.
    boolean hasDocValues()  
    NamedAnalyzer indexAnalyzer()  
    org.apache.lucene.queries.intervals.IntervalsSource intervals​(java.lang.String query, int max_gaps, boolean ordered, NamedAnalyzer analyzer, boolean prefix)
    Create an IntervalsSource to be used for proximity queries
    boolean isAggregatable()
    Returns true if the field is aggregatable.
    MappedFieldType.Relation isFieldWithinQuery​(org.apache.lucene.index.IndexReader reader, java.lang.Object from, java.lang.Object to, boolean includeLower, boolean includeUpper, java.time.ZoneId timeZone, DateMathParser dateMathParser, QueryRewriteContext context)
    Return whether all values of the given IndexReader are within the range, outside the range or cross the range.
    boolean isSearchable()
    Returns true if the field is searchable.
    java.util.Map<java.lang.String,​java.lang.String> meta()
    Get the metadata associated with this field.
    org.apache.lucene.search.Query multiPhraseQuery​(org.apache.lucene.analysis.TokenStream stream, int slop, boolean enablePositionIncrements)  
    java.lang.String name()  
    org.apache.lucene.search.Query phrasePrefixQuery​(org.apache.lucene.analysis.TokenStream stream, int slop, int maxExpansions)  
    org.apache.lucene.search.Query phraseQuery​(org.apache.lucene.analysis.TokenStream stream, int slop, boolean enablePositionIncrements)  
    java.util.function.Function<byte[],​java.lang.Number> pointReaderIfPossible()
    If the field supports using the indexed data to speed up operations related to ordering of data, such as sorting or aggs, return a function for doing that.
    org.apache.lucene.search.Query prefixQuery​(java.lang.String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, QueryShardContext context)  
    org.apache.lucene.search.Query rangeQuery​(java.lang.Object lowerTerm, java.lang.Object upperTerm, boolean includeLower, boolean includeUpper, ShapeRelation relation, java.time.ZoneId timeZone, DateMathParser parser, QueryShardContext context)
    Factory method for range queries.
    org.apache.lucene.search.Query regexpQuery​(java.lang.String value, int flags, int maxDeterminizedStates, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, QueryShardContext context)  
    void setBoost​(float boost)  
    void setEagerGlobalOrdinals​(boolean eagerGlobalOrdinals)  
    void setIndexAnalyzer​(NamedAnalyzer analyzer)  
    org.apache.lucene.search.spans.SpanQuery spanPrefixQuery​(java.lang.String value, org.apache.lucene.search.spans.SpanMultiTermQueryWrapper.SpanRewriteMethod method, QueryShardContext context)  
    abstract org.apache.lucene.search.Query termQuery​(java.lang.Object value, QueryShardContext context)
    Generates a query that will only match documents that contain the given value.
    org.apache.lucene.search.Query termsQuery​(java.util.List<?> values, QueryShardContext context)
    Build a constant-scoring query that matches all values.
    abstract java.lang.String typeName()
    Returns the name of this type, as would be specified in mapping properties
    void updateMeta​(java.util.Map<java.lang.String,​java.lang.String> meta)
    Associate metadata with this field.
    java.lang.Object valueForDisplay​(java.lang.Object value)
    Given a value that comes from the stored fields API, convert it to the expected type.
    org.apache.lucene.search.Query wildcardQuery​(java.lang.String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, QueryShardContext context)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MappedFieldType

      public MappedFieldType​(java.lang.String name, boolean isIndexed, boolean hasDocValues, TextSearchInfo textSearchInfo, java.util.Map<java.lang.String,​java.lang.String> meta)
  • Method Details

    • fielddataBuilder

      public IndexFieldData.Builder fielddataBuilder​(java.lang.String fullyQualifiedIndexName)
      Return a fielddata builder for this field
      Parameters:
      fullyQualifiedIndexName - the name of the index this field-data is build for
      Throws:
      java.lang.IllegalArgumentException - if the fielddata is not supported on this type. An IllegalArgumentException is needed in order to return an http error 400 when this error occurs in a request. see: ExceptionsHelper.status(java.lang.Throwable)
    • typeName

      public abstract java.lang.String typeName()
      Returns the name of this type, as would be specified in mapping properties
    • familyTypeName

      public java.lang.String familyTypeName()
      Returns the field family type, as used in field capabilities
    • name

      public java.lang.String name()
    • boost

      public float boost()
    • setBoost

      public void setBoost​(float boost)
    • hasDocValues

      public boolean hasDocValues()
    • indexAnalyzer

      public NamedAnalyzer indexAnalyzer()
    • setIndexAnalyzer

      public void setIndexAnalyzer​(NamedAnalyzer analyzer)
    • valueForDisplay

      public java.lang.Object valueForDisplay​(java.lang.Object value)
      Given a value that comes from the stored fields API, convert it to the expected type. For instance a date field would store dates as longs and format it back to a string in this method.
    • isSearchable

      public boolean isSearchable()
      Returns true if the field is searchable.
    • pointReaderIfPossible

      @Nullable public java.util.function.Function<byte[],​java.lang.Number> pointReaderIfPossible()
      If the field supports using the indexed data to speed up operations related to ordering of data, such as sorting or aggs, return a function for doing that. If it is unsupported for this field type, there is no need to override this method.
      Returns:
      null if the optimization cannot be applied, otherwise a function to use for the optimization
    • isAggregatable

      public boolean isAggregatable()
      Returns true if the field is aggregatable.
    • termQuery

      public abstract org.apache.lucene.search.Query termQuery​(java.lang.Object value, @Nullable QueryShardContext context)
      Generates a query that will only match documents that contain the given value. The default implementation returns a TermQuery over the value bytes, boosted by boost().
      Throws:
      java.lang.IllegalArgumentException - if value cannot be converted to the expected data type or if the field is not searchable due to the way it is configured (eg. not indexed)
      ElasticsearchParseException - if value cannot be converted to the expected data type
      java.lang.UnsupportedOperationException - if the field is not searchable regardless of options
      QueryShardException - if the field is not searchable regardless of options
    • termsQuery

      public org.apache.lucene.search.Query termsQuery​(java.util.List<?> values, @Nullable QueryShardContext context)
      Build a constant-scoring query that matches all values. The default implementation uses a ConstantScoreQuery around a BooleanQuery whose BooleanClause.Occur.SHOULD clauses are generated with termQuery(java.lang.Object, org.elasticsearch.index.query.QueryShardContext).
    • rangeQuery

      public org.apache.lucene.search.Query rangeQuery​(java.lang.Object lowerTerm, java.lang.Object upperTerm, boolean includeLower, boolean includeUpper, ShapeRelation relation, java.time.ZoneId timeZone, DateMathParser parser, QueryShardContext context)
      Factory method for range queries.
      Parameters:
      relation - the relation, nulls should be interpreted like INTERSECTS
    • fuzzyQuery

      public org.apache.lucene.search.Query fuzzyQuery​(java.lang.Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions, QueryShardContext context)
    • prefixQuery

      public org.apache.lucene.search.Query prefixQuery​(java.lang.String value, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod method, QueryShardContext context)
    • wildcardQuery

      public org.apache.lucene.search.Query wildcardQuery​(java.lang.String value, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod method, QueryShardContext context)
    • regexpQuery

      public org.apache.lucene.search.Query regexpQuery​(java.lang.String value, int flags, int maxDeterminizedStates, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod method, QueryShardContext context)
    • existsQuery

      public abstract org.apache.lucene.search.Query existsQuery​(QueryShardContext context)
    • phraseQuery

      public org.apache.lucene.search.Query phraseQuery​(org.apache.lucene.analysis.TokenStream stream, int slop, boolean enablePositionIncrements) throws java.io.IOException
      Throws:
      java.io.IOException
    • multiPhraseQuery

      public org.apache.lucene.search.Query multiPhraseQuery​(org.apache.lucene.analysis.TokenStream stream, int slop, boolean enablePositionIncrements) throws java.io.IOException
      Throws:
      java.io.IOException
    • phrasePrefixQuery

      public org.apache.lucene.search.Query phrasePrefixQuery​(org.apache.lucene.analysis.TokenStream stream, int slop, int maxExpansions) throws java.io.IOException
      Throws:
      java.io.IOException
    • spanPrefixQuery

      public org.apache.lucene.search.spans.SpanQuery spanPrefixQuery​(java.lang.String value, org.apache.lucene.search.spans.SpanMultiTermQueryWrapper.SpanRewriteMethod method, QueryShardContext context)
    • intervals

      public org.apache.lucene.queries.intervals.IntervalsSource intervals​(java.lang.String query, int max_gaps, boolean ordered, NamedAnalyzer analyzer, boolean prefix) throws java.io.IOException
      Create an IntervalsSource to be used for proximity queries
      Throws:
      java.io.IOException
    • isFieldWithinQuery

      public MappedFieldType.Relation isFieldWithinQuery​(org.apache.lucene.index.IndexReader reader, java.lang.Object from, java.lang.Object to, boolean includeLower, boolean includeUpper, java.time.ZoneId timeZone, DateMathParser dateMathParser, QueryRewriteContext context) throws java.io.IOException
      Return whether all values of the given IndexReader are within the range, outside the range or cross the range. The default implementation returns MappedFieldType.Relation.INTERSECTS, which is always fine to return when there is no way to check whether values are actually within bounds.
      Throws:
      java.io.IOException
    • failIfNoDocValues

      protected final void failIfNoDocValues()
      Throws:
      java.lang.IllegalArgumentException - if the fielddata is not supported on this type. An IllegalArgumentException is needed in order to return an http error 400 when this error occurs in a request. see: ExceptionsHelper.status(java.lang.Throwable)
    • failIfNotIndexed

      protected final void failIfNotIndexed()
    • eagerGlobalOrdinals

      public boolean eagerGlobalOrdinals()
    • setEagerGlobalOrdinals

      public void setEagerGlobalOrdinals​(boolean eagerGlobalOrdinals)
    • docValueFormat

      public DocValueFormat docValueFormat​(@Nullable java.lang.String format, java.time.ZoneId timeZone)
      Return a DocValueFormat that can be used to display and parse values as returned by the fielddata API. The default implementation returns a DocValueFormat.RAW.
    • extractTerm

      public static org.apache.lucene.index.Term extractTerm​(org.apache.lucene.search.Query termQuery)
      Extract a Term from a query created with termQuery(java.lang.Object, org.elasticsearch.index.query.QueryShardContext) by recursively removing BoostQuery wrappers.
      Throws:
      java.lang.IllegalArgumentException - if the wrapped query is not a TermQuery
    • meta

      public java.util.Map<java.lang.String,​java.lang.String> meta()
      Get the metadata associated with this field.
    • updateMeta

      public void updateMeta​(java.util.Map<java.lang.String,​java.lang.String> meta)
      Associate metadata with this field.
    • getTextSearchInfo

      public TextSearchInfo getTextSearchInfo()
      Returns information on how any text in this field is indexed Fields that do not support any text-based queries should return TextSearchInfo.NONE. Some fields (eg numeric) may support only simple match queries, and can return TextSearchInfo.SIMPLE_MATCH_ONLY