Class MappedFieldType

Direct Known Subclasses:
AbstractGeometryFieldMapper.AbstractGeometryFieldType, BinaryFieldMapper.BinaryFieldType, BooleanScriptFieldType, ConstantFieldType, DataStreamTimestampFieldMapper.TimestampFieldType, 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
      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
      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.
      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.
      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.
    • isDimension

      public boolean isDimension()
      true if field has been marked as a dimension field
    • termQuery

      public abstract 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().
      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 termQueryCaseInsensitive(Object value, @Nullable SearchExecutionContext context)
    • termsQuery

      public 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 rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, ShapeRelation relation, ZoneId timeZone, DateMathParser parser, SearchExecutionContext context)
      Factory method for range queries.
      relation - the relation, nulls should be interpreted like INTERSECTS
    • fuzzyQuery

      public fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions, SearchExecutionContext context)
    • prefixQuery

      public final prefixQuery(String value, @Nullable method, SearchExecutionContext context)
    • prefixQuery

      public prefixQuery(String value, @Nullable method, boolean caseInsensitve, SearchExecutionContext context)
    • wildcardQuery

      public final wildcardQuery(String value, @Nullable method, SearchExecutionContext context)
    • wildcardQuery

      public wildcardQuery(String value, @Nullable method, boolean caseInsensitve, SearchExecutionContext context)
    • normalizedWildcardQuery

      public normalizedWildcardQuery(String value, @Nullable method, SearchExecutionContext context)
    • regexpQuery

      public regexpQuery(String value, int syntaxFlags, int matchFlags, int maxDeterminizedStates, @Nullable method, SearchExecutionContext context)
    • existsQuery

      public existsQuery(SearchExecutionContext context)
    • phraseQuery

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

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

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

      public spanPrefixQuery(String value, method, SearchExecutionContext context)
    • distanceFeatureQuery

      public 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.
    • failIfNoDocValues

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

      public DocValueFormat docValueFormat(@Nullable String format, ZoneId timeZone)
      Pick a DocValueFormat that can be used to display and parse values of fields of this type.
    • checkNoFormat

      protected void checkNoFormat(@Nullable String format)
      Validate the provided format is null.
    • checkNoTimeZone

      protected void checkNoTimeZone(@Nullable ZoneId timeZone)
      Validate the provided timeZone is null.
    • extractTerm

      public static org.apache.lucene.index.Term extractTerm( termQuery)
      Extract a Term from a query created with termQuery(java.lang.Object, org.elasticsearch.index.query.SearchExecutionContext) by recursively removing BoostQuery wrappers.
      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.
      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)
      null or an enumeration of matching terms and their doc frequencies
      IOException - Errors accessing data