Package org.elasticsearch.index.mapper
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
This defines the core properties and functions to operate on a field.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classAn 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 TypeMethodDescriptionfloatboost()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)Return aDocValueFormatthat can be used to display and parse values as returned by the fielddata API.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 voidprotected voidReturns the field family type, as used in field capabilitiesfielddataBuilder(String fullyQualifiedIndexName, Supplier<SearchLookup> searchLookup)Return a fielddata builder for this fieldorg.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.index.TermsEnumgetTerms(boolean caseInsensitive, String string, SearchExecutionContext queryShardContext, 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.booleanbooleanReturns true if the field is aggregatable.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 givenIndexReaderare within the range, outside the range or cross the range.booleanReturns true if the field is searchable.booleanisStored()Returns true if the field is stored separately.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)org.apache.lucene.search.QueryprefixQuery(String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context)org.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.search.QueryregexpQuery(String value, int syntaxFlags, int matchFlags, int maxDeterminizedStates, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, SearchExecutionContext context)voidsetBoost(float boost)org.apache.lucene.search.spans.SpanQueryspanPrefixQuery(String value, org.apache.lucene.search.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 propertiesabstract 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.QuerywildcardQuery(String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, boolean caseInsensitve, SearchExecutionContext context)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
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 forsearchLookup- aSearchLookupsupplier 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
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 throw
UnsupportedOperationExceptionsince 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
-
boost
public float boost() -
setBoost
public void setBoost(float boost) -
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. -
isStored
public 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. -
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, boosted byboost().- 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) -
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.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 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. -
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 IOExceptionReturn 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() -
eagerGlobalOrdinals
public boolean eagerGlobalOrdinals()- Returns:
- if this field type should load global ordinals eagerly
-
docValueFormat
Return aDocValueFormatthat can be used to display and parse values as returned by the fielddata API. The default implementation returns aDocValueFormat.RAW. -
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(boolean caseInsensitive, String string, SearchExecutionContext queryShardContext, String searchAfter) throws IOExceptionThis 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 insensitivestring- the partially complete word the user has typed (can be empty)queryShardContext- the shard contextsearchAfter- - 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
-