java.lang.Object
org.elasticsearch.index.mapper.MappedFieldType
- Direct Known Subclasses:
AbstractGeometryFieldMapper.AbstractGeometryFieldType
,AbstractScriptFieldType
,BinaryFieldMapper.BinaryFieldType
,ConstantFieldType
,DataStreamTimestampFieldMapper.TimestampFieldType
,DateFieldMapper.DateFieldType
,DocCountFieldMapper.DocCountFieldType
,InferenceMetadataFieldsMapper.InferenceMetadataFieldType
,LookupRuntimeFieldType
,PlaceHolderFieldMapper.PlaceHolderFieldType
,RangeFieldMapper.RangeFieldType
,SimpleMappedFieldType
,SparseVectorFieldMapper.SparseVectorFieldType
,TimeSeriesIdFieldMapper.TimeSeriesIdFieldType
This defines the core properties and functions to operate on a field.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static enum
static enum
Operation to specify what data structures are used to retrieve field data from and generate a representation of doc values.static enum
static enum
An enum used to describe the relation between the range of terms in a shard when compared with a query range -
Constructor Summary
ConstructorsConstructorDescriptionMappedFieldType
(String name, boolean isIndexed, boolean isStored, boolean hasDocValues, TextSearchInfo textSearchInfo, Map<String, String> meta) -
Method Summary
Modifier and TypeMethodDescriptionblockLoader
(MappedFieldType.BlockLoaderContext blContext) Returns a loader for ESQL ornull
if the field doesn't support ESQL.protected void
checkNoFormat
(String format) Validate the providedformat
is null.protected void
checkNoTimeZone
(ZoneId timeZone) Validate the providedtimeZone
is null.Returns the collapse type of the field CollapseType.NONE means the field can'be used for collapsing.org.apache.lucene.search.Query
distanceFeatureQuery
(Object origin, String pivot, SearchExecutionContext context) docValueFormat
(String format, ZoneId timeZone) Pick aDocValueFormat
that can be used to display and parse values of fields of this type.boolean
org.apache.lucene.search.Query
existsQuery
(SearchExecutionContext context) protected final void
protected final void
protected final void
Returns the field family type, as used in field capabilitiesfielddataBuilder
(FieldDataContext fieldDataContext) Return a fielddata builder for this fieldboolean
fieldHasValue
(org.apache.lucene.index.FieldInfos fieldInfos) This method is used to support _field_caps when include_empty_fields is set tofalse
.org.apache.lucene.queries.intervals.IntervalsSource
fuzzyIntervals
(String term, int maxDistance, int prefixLength, boolean transpositions, SearchExecutionContext context) Create a fuzzyIntervalsSource
for the given term.org.apache.lucene.search.Query
fuzzyQuery
(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions, SearchExecutionContext context) org.apache.lucene.search.Query
fuzzyQuery
(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions, SearchExecutionContext context, org.apache.lucene.search.MultiTermQuery.RewriteMethod rewriteMethod) Returns the default highlighter type to use when highlighting the field.org.apache.lucene.index.TermsEnum
getTerms
(org.apache.lucene.index.IndexReader reader, String prefix, boolean caseInsensitive, String searchAfter) This method is used to support auto-complete services and implementations are expected to find terms beginning with the provided string very quickly.Returns information on how any text in this field is indexed Fields that do not support any text-based queries should returnTextSearchInfo.NONE
.boolean
boolean
boolean
Returns true if the field is aggregatable.boolean
isFieldWithinQuery
(org.apache.lucene.index.IndexReader reader, Object from, Object to, boolean includeLower, boolean includeUpper, ZoneId timeZone, DateMathParser dateMathParser, QueryRewriteContext context) Return whether all values of the givenIndexReader
are within the range, outside the range or cross the range.final boolean
Returns true if the field is indexed.boolean
Returns true if the field is searchable.final boolean
isStored()
Returns true if the field is stored separately.boolean
mayExistInIndex
(SearchExecutionContext context) meta()
Get the metadata associated with this field.org.apache.lucene.search.Query
multiPhraseQuery
(org.apache.lucene.analysis.TokenStream stream, int slop, boolean enablePositionIncrements, SearchExecutionContext context) name()
org.apache.lucene.search.Query
normalizedWildcardQuery
(String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context) org.apache.lucene.search.Query
phrasePrefixQuery
(org.apache.lucene.analysis.TokenStream stream, int slop, int maxExpansions, SearchExecutionContext context) org.apache.lucene.search.Query
phraseQuery
(org.apache.lucene.analysis.TokenStream stream, int slop, boolean enablePositionIncrements, SearchExecutionContext context) 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.queries.intervals.IntervalsSource
prefixIntervals
(org.apache.lucene.util.BytesRef prefix, SearchExecutionContext context) Create anIntervalsSource
for the given prefix.org.apache.lucene.search.Query
prefixQuery
(String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, boolean caseInsensitve, SearchExecutionContext context) final org.apache.lucene.search.Query
prefixQuery
(String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context) org.apache.lucene.queries.intervals.IntervalsSource
rangeIntervals
(org.apache.lucene.util.BytesRef lowerTerm, org.apache.lucene.util.BytesRef upperTerm, boolean includeLower, boolean includeUpper, SearchExecutionContext context) Create a rangeIntervalsSource
for the given rangesorg.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.org.apache.lucene.queries.intervals.IntervalsSource
regexpIntervals
(org.apache.lucene.util.BytesRef pattern, SearchExecutionContext context) Create a regexpIntervalsSource
for the given pattern.org.apache.lucene.search.Query
regexpQuery
(String value, int syntaxFlags, int matchFlags, int maxDeterminizedStates, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context) org.apache.lucene.queries.spans.SpanQuery
spanPrefixQuery
(String value, org.apache.lucene.queries.spans.SpanMultiTermQueryWrapper.SpanRewriteMethod method, SearchExecutionContext context) org.apache.lucene.queries.intervals.IntervalsSource
termIntervals
(org.apache.lucene.util.BytesRef term, SearchExecutionContext context) Create anIntervalsSource
for the given term.abstract org.apache.lucene.search.Query
termQuery
(Object value, SearchExecutionContext context) Generates a query that will only match documents that contain the given value.org.apache.lucene.search.Query
termQueryCaseInsensitive
(Object value, SearchExecutionContext context) org.apache.lucene.search.Query
termsQuery
(Collection<?> values, SearchExecutionContext context) Build a constant-scoring query that matches all values.abstract String
typeName()
Returns the name of this type, as would be specified in mapping propertiesvoid
validateMatchedRoutingPath
(String routingPath) Validate that this field can be the target ofIndexMetadata.INDEX_ROUTING_PATH
.abstract ValueFetcher
valueFetcher
(SearchExecutionContext context, String format) Create a helper class to fetch field values during theFetchFieldsPhase
.valueForDisplay
(Object value) Given a value that comes from the stored fields API, convert it to the expected type.org.apache.lucene.queries.intervals.IntervalsSource
wildcardIntervals
(org.apache.lucene.util.BytesRef pattern, SearchExecutionContext context) Create a wildcardIntervalsSource
for the given pattern.org.apache.lucene.search.Query
wildcardQuery
(String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, boolean caseInsensitve, SearchExecutionContext context) final org.apache.lucene.search.Query
wildcardQuery
(String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context)
-
Constructor Details
-
MappedFieldType
public MappedFieldType(String name, boolean isIndexed, boolean isStored, boolean hasDocValues, TextSearchInfo textSearchInfo, Map<String, String> meta)
-
-
Method Details
-
fielddataBuilder
Return a fielddata builder for this field- Parameters:
fieldDataContext
- the context for the fielddata- 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
Create a helper class to fetch field values during theFetchFieldsPhase
. New field types must implement this method in order to support the search 'fields' option. Except for metadata fields, field types should not throwUnsupportedOperationException
since this could cause a search retrieving multiple fields (like "fields": ["*"]) to fail. -
typeName
Returns the name of this type, as would be specified in mapping properties -
familyTypeName
Returns the field family type, as used in field capabilities -
name
-
hasDocValues
public boolean hasDocValues() -
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
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. -
isIndexed
public final boolean isIndexed()Returns true if the field is indexed. -
isStored
public final boolean isStored()Returns true if the field is stored separately. -
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. -
isDimension
public boolean isDimension()- Returns:
- true if field has been marked as a dimension field
-
hasScriptValues
public boolean hasScriptValues()- Returns:
- true if field has script values.
-
dimensions
- Returns:
- a list of dimension fields. Expected to be used by fields that have nested fields or that, in some way, identify a collection of fields by means of a top level field (like flattened fields).
-
getMetricType
- Returns:
- metric type or null if the field is not a metric field
-
getDefaultHighlighter
Returns the default highlighter type to use when highlighting the field. -
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 aTermQuery
over the value bytes- Throws:
IllegalArgumentException
- ifvalue
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
- ifvalue
cannot be converted to the expected data typeUnsupportedOperationException
- if the field is not searchable regardless of optionsQueryShardException
- 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 aConstantScoreQuery
around aBooleanQuery
whoseBooleanClause.Occur.SHOULD
clauses are generated withtermQuery(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, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod rewriteMethod) -
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
-
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.queries.spans.SpanQuery spanPrefixQuery(String value, org.apache.lucene.queries.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 anIntervalsSource
for the given term. -
prefixIntervals
public org.apache.lucene.queries.intervals.IntervalsSource prefixIntervals(org.apache.lucene.util.BytesRef prefix, SearchExecutionContext context) Create anIntervalsSource
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 fuzzyIntervalsSource
for the given term. -
wildcardIntervals
public org.apache.lucene.queries.intervals.IntervalsSource wildcardIntervals(org.apache.lucene.util.BytesRef pattern, SearchExecutionContext context) Create a wildcardIntervalsSource
for the given pattern. -
regexpIntervals
public org.apache.lucene.queries.intervals.IntervalsSource regexpIntervals(org.apache.lucene.util.BytesRef pattern, SearchExecutionContext context) Create a regexpIntervalsSource
for the given pattern. -
rangeIntervals
public org.apache.lucene.queries.intervals.IntervalsSource rangeIntervals(org.apache.lucene.util.BytesRef lowerTerm, org.apache.lucene.util.BytesRef upperTerm, boolean includeLower, boolean includeUpper, SearchExecutionContext context) Create a rangeIntervalsSource
for the given ranges -
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 givenIndexReader
are within the range, outside the range or cross the range. The default implementation returnsMappedFieldType.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() -
failIfNotIndexedNorDocValuesFallback
-
eagerGlobalOrdinals
public boolean eagerGlobalOrdinals()- Returns:
- if this field type should load global ordinals eagerly
-
mayExistInIndex
- Returns:
- if the field may have values in the underlying index
Note that this should only return
false
if it is not possible for it to match on a term query. - See Also:
-
docValueFormat
Pick aDocValueFormat
that can be used to display and parse values of fields of this type. -
checkNoFormat
Validate the providedformat
is null. -
checkNoTimeZone
Validate the providedtimeZone
is null. -
meta
Get the metadata associated with this field. -
getTextSearchInfo
Returns information on how any text in this field is indexed Fields that do not support any text-based queries should returnTextSearchInfo.NONE
. Some fields (eg keyword) may support only simple match queries, and can returnTextSearchInfo.SIMPLE_MATCH_ONLY
; other fields may support simple match queries without using the terms index, and can returnTextSearchInfo.SIMPLE_MATCH_WITHOUT_TERMS
-
getTerms
public org.apache.lucene.index.TermsEnum getTerms(org.apache.lucene.index.IndexReader reader, String prefix, boolean caseInsensitive, 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:
reader
- an index readerprefix
- the partially complete word the user has typed (can be empty)caseInsensitive
- if prefix matches should be case insensitivesearchAfter
- - 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
- Throws:
IOException
- Errors accessing data
-
validateMatchedRoutingPath
Validate that this field can be the target ofIndexMetadata.INDEX_ROUTING_PATH
. -
fieldHasValue
public boolean fieldHasValue(org.apache.lucene.index.FieldInfos fieldInfos) This method is used to support _field_caps when include_empty_fields is set tofalse
. In that case we return only fields with value in an index. This method gets as input FieldInfos and returns if the field is non-empty. This method needs to be overwritten where fields don't have footprint in Lucene or their name differs fromname()
- Parameters:
fieldInfos
- field information- Returns:
true
if field is present in fieldInfosfalse
otherwise
-
blockLoader
Returns a loader for ESQL ornull
if the field doesn't support ESQL.
-