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 interfacestatic enumstatic enumOperation to specify what data structures are used to retrieve field data from and generate a representation of doc values.static enumstatic enumAn 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 TypeMethodDescriptionorg.apache.lucene.search.QueryautomatonQuery(Supplier<org.apache.lucene.util.automaton.Automaton> automatonSupplier, Supplier<org.apache.lucene.util.automaton.CharacterRunAutomaton> characterRunAutomatonSupplier, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context, String description) Returns a Lucine pushable Query for the current field For now can only be AutomatonQuery or MatchAllDocsQuery() or MatchNoDocsQuery()blockLoader(MappedFieldType.BlockLoaderContext blContext) Returns a loader for ESQL ornullif the field doesn't support ESQL.protected voidcheckNoFormat(String format) Validate the providedformatis null.protected voidcheckNoTimeZone(ZoneId timeZone) Validate the providedtimeZoneis null.Returns the collapse type of the field CollapseType.NONE means the field can'be used for collapsing.org.apache.lucene.search.QuerydistanceFeatureQuery(Object origin, String pivot, SearchExecutionContext context) docValueFormat(String format, ZoneId timeZone) Pick aDocValueFormatthat can be used to display and parse values of fields of this type.booleanorg.apache.lucene.search.QueryexistsQuery(SearchExecutionContext context) static org.apache.lucene.index.TermextractTerm(org.apache.lucene.search.Query termQuery) Extract aTermfrom a query created withtermQuery(java.lang.Object, org.elasticsearch.index.query.SearchExecutionContext)by recursively removingBoostQuerywrappers.protected final voidprotected final voidprotected final voidReturns the field family type, as used in field capabilitiesfielddataBuilder(FieldDataContext fieldDataContext) Return a fielddata builder for this fieldbooleanfieldHasValue(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.IntervalsSourcefuzzyIntervals(String term, int maxDistance, int prefixLength, boolean transpositions, SearchExecutionContext context) Create a fuzzyIntervalsSourcefor the given term.org.apache.lucene.search.QueryfuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions, SearchExecutionContext context) org.apache.lucene.search.QueryfuzzyQuery(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.TermsEnumgetTerms(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.booleanbooleanbooleanReturns true if the field is aggregatable.booleanisFieldWithinQuery(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 givenIndexReaderare within the range, outside the range or cross the range.final booleanReturns true if the field is indexed.booleanReturns true if the field is searchable.final booleanisStored()Returns true if the field is stored separately.booleanVector embeddings are typically large and not intended for human consumption, so such fields may be excluded from responses.booleanmayExistInIndex(SearchExecutionContext context) meta()Get the metadata associated with this field.org.apache.lucene.search.QuerymultiPhraseQuery(org.apache.lucene.analysis.TokenStream stream, int slop, boolean enablePositionIncrements, SearchExecutionContext context) name()org.apache.lucene.search.QuerynormalizedWildcardQuery(String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context) org.apache.lucene.search.QueryphrasePrefixQuery(org.apache.lucene.analysis.TokenStream stream, int slop, int maxExpansions, SearchExecutionContext context) org.apache.lucene.search.QueryphraseQuery(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.IntervalsSourceprefixIntervals(org.apache.lucene.util.BytesRef prefix, SearchExecutionContext context) Create anIntervalsSourcefor the given prefix.org.apache.lucene.search.QueryprefixQuery(String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, boolean caseInsensitve, SearchExecutionContext context) final org.apache.lucene.search.QueryprefixQuery(String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context) org.apache.lucene.queries.intervals.IntervalsSourcerangeIntervals(org.apache.lucene.util.BytesRef lowerTerm, org.apache.lucene.util.BytesRef upperTerm, boolean includeLower, boolean includeUpper, SearchExecutionContext context) Create a rangeIntervalsSourcefor the given rangesorg.apache.lucene.search.QueryrangeQuery(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.IntervalsSourceregexpIntervals(org.apache.lucene.util.BytesRef pattern, SearchExecutionContext context) Create a regexpIntervalsSourcefor the given pattern.org.apache.lucene.search.QueryregexpQuery(String value, int syntaxFlags, int matchFlags, int maxDeterminizedStates, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context) org.apache.lucene.queries.spans.SpanQueryspanPrefixQuery(String value, org.apache.lucene.queries.spans.SpanMultiTermQueryWrapper.SpanRewriteMethod method, SearchExecutionContext context) org.apache.lucene.queries.intervals.IntervalsSourcetermIntervals(org.apache.lucene.util.BytesRef term, SearchExecutionContext context) Create anIntervalsSourcefor the given term.abstract org.apache.lucene.search.QuerytermQuery(Object value, SearchExecutionContext context) Generates a query that will only match documents that contain the given value.org.apache.lucene.search.QuerytermQueryCaseInsensitive(Object value, SearchExecutionContext context) org.apache.lucene.search.QuerytermsQuery(Collection<?> values, SearchExecutionContext context) Build a constant-scoring query that matches all values.abstract StringtypeName()Returns the name of this type, as would be specified in mapping propertiesvoidvalidateMatchedRoutingPath(String routingPath) Validate that this field can be the target ofIndexMetadata.INDEX_ROUTING_PATH.abstract ValueFetchervalueFetcher(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.IntervalsSourcewildcardIntervals(org.apache.lucene.util.BytesRef pattern, SearchExecutionContext context) Create a wildcardIntervalsSourcefor the given pattern.org.apache.lucene.search.QuerywildcardLikeQuery(String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, boolean caseInsensitve, SearchExecutionContext context) Similar to wildcardQuery, except that we change the behavior for ESQL to behave like a string LIKE query, where the value is matched as a stringorg.apache.lucene.search.QuerywildcardQuery(String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, boolean caseInsensitve, SearchExecutionContext context) final org.apache.lucene.search.QuerywildcardQuery(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 throwUnsupportedOperationExceptionsince 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
-
isVectorEmbedding
public boolean isVectorEmbedding()Vector embeddings are typically large and not intended for human consumption, so such fields may be excluded from responses.- Returns:
- true if this field contains vector embeddings.
-
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 aTermQueryover the value bytes- Throws:
IllegalArgumentException- ifvaluecannot 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- ifvaluecannot 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 aConstantScoreQueryaround aBooleanQuerywhoseBooleanClause.Occur.SHOULDclauses 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) -
wildcardLikeQuery
public org.apache.lucene.search.Query wildcardLikeQuery(String value, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod method, boolean caseInsensitve, SearchExecutionContext context) Similar to wildcardQuery, except that we change the behavior for ESQL to behave like a string LIKE query, where the value is matched as a string -
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) -
automatonQuery
public org.apache.lucene.search.Query automatonQuery(Supplier<org.apache.lucene.util.automaton.Automaton> automatonSupplier, Supplier<org.apache.lucene.util.automaton.CharacterRunAutomaton> characterRunAutomatonSupplier, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context, String description) Returns a Lucine pushable Query for the current field For now can only be AutomatonQuery or MatchAllDocsQuery() or MatchNoDocsQuery() -
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 anIntervalsSourcefor the given term. -
prefixIntervals
public org.apache.lucene.queries.intervals.IntervalsSource prefixIntervals(org.apache.lucene.util.BytesRef prefix, SearchExecutionContext context) Create anIntervalsSourcefor the given prefix. -
fuzzyIntervals
public org.apache.lucene.queries.intervals.IntervalsSource fuzzyIntervals(String term, int maxDistance, int prefixLength, boolean transpositions, SearchExecutionContext context) Create a fuzzyIntervalsSourcefor the given term. -
wildcardIntervals
public org.apache.lucene.queries.intervals.IntervalsSource wildcardIntervals(org.apache.lucene.util.BytesRef pattern, SearchExecutionContext context) Create a wildcardIntervalsSourcefor the given pattern. -
regexpIntervals
public org.apache.lucene.queries.intervals.IntervalsSource regexpIntervals(org.apache.lucene.util.BytesRef pattern, SearchExecutionContext context) Create a regexpIntervalsSourcefor 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 rangeIntervalsSourcefor 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 givenIndexReaderare 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
falseif it is not possible for it to match on a term query. - See Also:
-
docValueFormat
Pick aDocValueFormatthat can be used to display and parse values of fields of this type. -
checkNoFormat
Validate the providedformatis null. -
checkNoTimeZone
Validate the providedtimeZoneis null. -
extractTerm
public static org.apache.lucene.index.Term extractTerm(org.apache.lucene.search.Query termQuery) Extract aTermfrom a query created withtermQuery(java.lang.Object, org.elasticsearch.index.query.SearchExecutionContext)by recursively removingBoostQuerywrappers.- Throws:
IllegalArgumentException- if the wrapped query is not aTermQuery
-
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:
trueif field is present in fieldInfosfalseotherwise
-
blockLoader
Returns a loader for ESQL ornullif the field doesn't support ESQL.
-