Class MappedFieldType

java.lang.Object
org.elasticsearch.index.mapper.MappedFieldType
Direct Known Subclasses:
AbstractGeometryFieldMapper.AbstractGeometryFieldType, BinaryFieldMapper.BinaryFieldType, BooleanScriptFieldType, ConstantFieldType, DateFieldMapper.DateFieldType, DateScriptFieldType, DocCountFieldMapper.DocCountFieldType, DoubleScriptFieldType, GeoPointScriptFieldType, IpScriptFieldType, KeywordScriptFieldType, LongScriptFieldType, RangeFieldMapper.RangeFieldType, SimpleMappedFieldType

public abstract class MappedFieldType extends Object
This defines the core properties and functions to operate on a field.
  • Constructor Details

    • MappedFieldType

      public MappedFieldType(String name, boolean isIndexed, boolean isStored, boolean hasDocValues, TextSearchInfo textSearchInfo, Map<String,String> meta)
  • Method Details

    • fielddataBuilder

      public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, Supplier<SearchLookup> searchLookup)
      Return a fielddata builder for this field
      Parameters:
      fullyQualifiedIndexName - the name of the index this field-data is build for
      searchLookup - a SearchLookup supplier to allow for accessing other fields values in the context of runtime fields
      Throws:
      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)
    • valueFetcher

      public abstract ValueFetcher valueFetcher(SearchExecutionContext context, @Nullable String format)
      Create a helper class to fetch field values during the FetchFieldsPhase.

      New field types must implement this method in order to support the search 'fields' option. Except for metadata fields, field types should not throw UnsupportedOperationException since this could cause a search retrieving multiple fields (like "fields": ["*"]) to fail.

    • typeName

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

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

      public String name()
    • boost

      public float boost()
    • setBoost

      public void setBoost(float boost)
    • hasDocValues

      public boolean hasDocValues()
    • collapseType

      public MappedFieldType.CollapseType collapseType()
      Returns the collapse type of the field CollapseType.NONE means the field can'be used for collapsing.
      Returns:
      collapse type of the field
    • valueForDisplay

      public Object valueForDisplay(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.
    • isStored

      public boolean isStored()
      Returns true if the field is stored separately.
    • pointReaderIfPossible

      @Nullable public Function<byte[],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(Object value, @Nullable SearchExecutionContext 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:
      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
      UnsupportedOperationException - if the field is not searchable regardless of options
      QueryShardException - if the field is not searchable regardless of options
    • termQueryCaseInsensitive

      public org.apache.lucene.search.Query termQueryCaseInsensitive(Object value, @Nullable SearchExecutionContext context)
    • termsQuery

      public org.apache.lucene.search.Query termsQuery(Collection<?> values, @Nullable SearchExecutionContext 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.SearchExecutionContext).
    • rangeQuery

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

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

      public final org.apache.lucene.search.Query prefixQuery(String value, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context)
    • prefixQuery

      public org.apache.lucene.search.Query prefixQuery(String value, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod method, boolean caseInsensitve, SearchExecutionContext context)
    • wildcardQuery

      public final org.apache.lucene.search.Query wildcardQuery(String value, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context)
    • wildcardQuery

      public org.apache.lucene.search.Query wildcardQuery(String value, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod method, boolean caseInsensitve, SearchExecutionContext context)
    • normalizedWildcardQuery

      public org.apache.lucene.search.Query normalizedWildcardQuery(String value, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context)
    • regexpQuery

      public org.apache.lucene.search.Query regexpQuery(String value, int syntaxFlags, int matchFlags, int maxDeterminizedStates, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context)
    • existsQuery

      public org.apache.lucene.search.Query existsQuery(SearchExecutionContext context)
    • phraseQuery

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

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

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

      public org.apache.lucene.search.spans.SpanQuery spanPrefixQuery(String value, org.apache.lucene.search.spans.SpanMultiTermQueryWrapper.SpanRewriteMethod method, SearchExecutionContext context)
    • distanceFeatureQuery

      public org.apache.lucene.search.Query distanceFeatureQuery(Object origin, String pivot, SearchExecutionContext context)
    • termIntervals

      public org.apache.lucene.queries.intervals.IntervalsSource termIntervals(org.apache.lucene.util.BytesRef term, SearchExecutionContext context)
      Create an IntervalsSource for the given term.
    • prefixIntervals

      public org.apache.lucene.queries.intervals.IntervalsSource prefixIntervals(org.apache.lucene.util.BytesRef prefix, SearchExecutionContext context)
      Create an IntervalsSource for the given prefix.
    • fuzzyIntervals

      public org.apache.lucene.queries.intervals.IntervalsSource fuzzyIntervals(String term, int maxDistance, int prefixLength, boolean transpositions, SearchExecutionContext context)
      Create a fuzzy IntervalsSource for the given term.
    • wildcardIntervals

      public org.apache.lucene.queries.intervals.IntervalsSource wildcardIntervals(org.apache.lucene.util.BytesRef pattern, SearchExecutionContext context)
      Create a wildcard IntervalsSource for the given pattern.
    • isFieldWithinQuery

      public MappedFieldType.Relation isFieldWithinQuery(org.apache.lucene.index.IndexReader reader, Object from, Object to, boolean includeLower, boolean includeUpper, ZoneId timeZone, DateMathParser dateMathParser, QueryRewriteContext context) throws 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:
      IOException
    • failIfNoDocValues

      protected final void failIfNoDocValues()
      Throws:
      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()
      Returns:
      if this field type should load global ordinals eagerly
    • docValueFormat

      public DocValueFormat docValueFormat(@Nullable String format, 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.SearchExecutionContext) by recursively removing BoostQuery wrappers.
      Throws:
      IllegalArgumentException - if the wrapped query is not a TermQuery
    • meta

      public Map<String,String> meta()
      Get the metadata associated 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 keyword) may support only simple match queries, and can return TextSearchInfo.SIMPLE_MATCH_ONLY; other fields may support simple match queries without using the terms index, and can return TextSearchInfo.SIMPLE_MATCH_WITHOUT_TERMS
    • getTerms

      public org.apache.lucene.index.TermsEnum getTerms(boolean caseInsensitive, String string, SearchExecutionContext queryShardContext, String searchAfter) throws IOException
      This method is used to support auto-complete services and implementations are expected to find terms beginning with the provided string very quickly. If fields cannot look up matching terms quickly they should return null. The returned TermEnum should implement next(), term() and doc_freq() methods but postings etc are not required.
      Parameters:
      caseInsensitive - if matches should be case insensitive
      string - the partially complete word the user has typed (can be empty)
      queryShardContext - the shard context
      searchAfter - - usually null. If supplied the TermsEnum result must be positioned after the provided term (used for pagination)
      Returns:
      null or an enumeration of matching terms and their doc frequencies
      Throws:
      IOException - Errors accessing data