Class MappedFieldType

java.lang.Object
org.apache.lucene.document.FieldType
org.elasticsearch.index.mapper.MappedFieldType
All Implemented Interfaces:
org.apache.lucene.index.IndexableFieldType
Direct Known Subclasses:
AbstractGeometryFieldMapper.AbstractGeometryFieldType, DateFieldMapper.DateFieldType, GeoPointFieldMapper.GeoPointFieldType, RangeFieldMapper.RangeFieldType, SimpleMappedFieldType

public abstract class MappedFieldType
extends org.apache.lucene.document.FieldType
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 
    Modifier Constructor Description
      MappedFieldType()  
    protected MappedFieldType​(MappedFieldType ref)  
  • Method Summary

    Modifier and Type Method Description
    float boost()  
    void checkCompatibility​(MappedFieldType other, java.util.List<java.lang.String> conflicts)
    Checks for any conflicts between this field type and other.
    abstract MappedFieldType clone()  
    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()  
    boolean equals​(java.lang.Object o)  
    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()  
    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)  
    boolean hasDocValues()  
    int hashCode()  
    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()  
    java.lang.Object nullValue()
    Returns the value that should be added when JSON null is found, or null if no value should be added
    java.lang.String nullValueAsString()
    Returns the null value stringified or null if there is no null value
    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)  
    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)  
    NamedAnalyzer searchAnalyzer()  
    NamedAnalyzer searchQuoteAnalyzer()  
    void setBoost​(float boost)  
    void setEagerGlobalOrdinals​(boolean eagerGlobalOrdinals)  
    void setHasDocValues​(boolean hasDocValues)  
    void setIndexAnalyzer​(NamedAnalyzer analyzer)  
    void setMeta​(java.util.Map<java.lang.String,​java.lang.String> meta)
    Associate metadata with this field.
    void setName​(java.lang.String name)  
    void setNullValue​(java.lang.Object nullValue)
    Sets the null value and initializes the string version
    void setSearchAnalyzer​(NamedAnalyzer analyzer)  
    void setSearchQuoteAnalyzer​(NamedAnalyzer analyzer)  
    void setSimilarity​(SimilarityProvider similarity)  
    SimilarityProvider similarity()  
    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
    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 org.apache.lucene.document.FieldType

    checkIfFrozen, docValuesType, freeze, getAttributes, indexOptions, omitNorms, pointDataDimensionCount, pointIndexDimensionCount, pointNumBytes, putAttribute, setDimensions, setDimensions, setDocValuesType, setIndexOptions, setOmitNorms, setStored, setStoreTermVectorOffsets, setStoreTermVectorPayloads, setStoreTermVectorPositions, setStoreTermVectors, setTokenized, stored, storeTermVectorOffsets, storeTermVectorPayloads, storeTermVectorPositions, storeTermVectors, tokenized, toString

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • clone

      public abstract MappedFieldType clone()
      Overrides:
      clone in class java.lang.Object
    • 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)
    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class org.apache.lucene.document.FieldType
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class org.apache.lucene.document.FieldType
    • typeName

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

      public void checkCompatibility​(MappedFieldType other, java.util.List<java.lang.String> conflicts)
      Checks for any conflicts between this field type and other. If strict is true, all properties must be equal. Otherwise, only properties which must never change in an index are checked.
    • name

      public java.lang.String name()
    • setName

      public void setName​(java.lang.String name)
    • boost

      public float boost()
    • setBoost

      public void setBoost​(float boost)
    • hasDocValues

      public boolean hasDocValues()
    • setHasDocValues

      public void setHasDocValues​(boolean hasDocValues)
    • indexAnalyzer

      public NamedAnalyzer indexAnalyzer()
    • setIndexAnalyzer

      public void setIndexAnalyzer​(NamedAnalyzer analyzer)
    • searchAnalyzer

      public NamedAnalyzer searchAnalyzer()
    • setSearchAnalyzer

      public void setSearchAnalyzer​(NamedAnalyzer analyzer)
    • searchQuoteAnalyzer

      public NamedAnalyzer searchQuoteAnalyzer()
    • setSearchQuoteAnalyzer

      public void setSearchQuoteAnalyzer​(NamedAnalyzer analyzer)
    • similarity

      public SimilarityProvider similarity()
    • setSimilarity

      public void setSimilarity​(SimilarityProvider similarity)
    • nullValue

      public java.lang.Object nullValue()
      Returns the value that should be added when JSON null is found, or null if no value should be added
    • nullValueAsString

      public java.lang.String nullValueAsString()
      Returns the null value stringified or null if there is no null value
    • setNullValue

      public void setNullValue​(java.lang.Object nullValue)
      Sets the null value and initializes the string version
    • 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.
    • 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)
    • 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.
    • setMeta

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