Package org.elasticsearch.index.mapper
Class MappedFieldType
java.lang.Object
org.apache.lucene.document.FieldType
org.elasticsearch.index.mapper.MappedFieldType
- All Implemented Interfaces:
org.apache.lucene.index.IndexableFieldType
- Direct Known Subclasses:
AbstractSearchableGeometryFieldType
,ConstantFieldType
,DateFieldMapper.DateFieldType
,RangeFieldMapper.RangeFieldType
,SimpleMappedFieldType
public abstract class MappedFieldType
extends org.apache.lucene.document.FieldType
This defines the core properties and functions to operate on a field.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MappedFieldType.Relation
An enum used to describe the relation between the range of terms in a shard when compared with a query range -
Constructor Summary
Constructors Modifier Constructor Description MappedFieldType()
protected
MappedFieldType(MappedFieldType ref)
-
Method Summary
Modifier and Type Method Description float
boost()
void
checkCompatibility(MappedFieldType other, java.util.List<java.lang.String> conflicts)
Checks for any conflicts between this field type and other.abstract MappedFieldType
clone()
DocValueFormat
docValueFormat(java.lang.String format, java.time.ZoneId timeZone)
Return aDocValueFormat
that can be used to display and parse values as returned by the fielddata API.boolean
eagerGlobalOrdinals()
boolean
equals(java.lang.Object o)
abstract org.apache.lucene.search.Query
existsQuery(QueryShardContext context)
static org.apache.lucene.index.Term
extractTerm(org.apache.lucene.search.Query termQuery)
Extract aTerm
from a query created withtermQuery(java.lang.Object, org.elasticsearch.index.query.QueryShardContext)
by recursively removingBoostQuery
wrappers.protected void
failIfNoDocValues()
protected void
failIfNotIndexed()
IndexFieldData.Builder
fielddataBuilder(java.lang.String fullyQualifiedIndexName)
Return a fielddata builder for this fieldorg.apache.lucene.search.Query
fuzzyQuery(java.lang.Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions, QueryShardContext context)
boolean
hasDocValues()
int
hashCode()
NamedAnalyzer
indexAnalyzer()
org.apache.lucene.queries.intervals.IntervalsSource
intervals(java.lang.String query, int max_gaps, boolean ordered, NamedAnalyzer analyzer, boolean prefix)
Create anIntervalsSource
to be used for proximity queriesboolean
isAggregatable()
Returns true if the field is aggregatable.MappedFieldType.Relation
isFieldWithinQuery(org.apache.lucene.index.IndexReader reader, java.lang.Object from, java.lang.Object to, boolean includeLower, boolean includeUpper, java.time.ZoneId timeZone, DateMathParser dateMathParser, QueryRewriteContext context)
Return whether all values of the givenIndexReader
are within the range, outside the range or cross the range.boolean
isSearchable()
Returns true if the field is searchable.java.util.Map<java.lang.String,java.lang.String>
meta()
Get the metadata associated with this field.org.apache.lucene.search.Query
multiPhraseQuery(org.apache.lucene.analysis.TokenStream stream, int slop, boolean enablePositionIncrements)
java.lang.String
name()
java.lang.Object
nullValue()
Returns the value that should be added when JSON null is found, or null if no value should be addedjava.lang.String
nullValueAsString()
Returns the null value stringified or null if there is no null valueorg.apache.lucene.search.Query
phrasePrefixQuery(org.apache.lucene.analysis.TokenStream stream, int slop, int maxExpansions)
org.apache.lucene.search.Query
phraseQuery(org.apache.lucene.analysis.TokenStream stream, int slop, boolean enablePositionIncrements)
org.apache.lucene.search.Query
prefixQuery(java.lang.String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, QueryShardContext context)
org.apache.lucene.search.Query
rangeQuery(java.lang.Object lowerTerm, java.lang.Object upperTerm, boolean includeLower, boolean includeUpper, ShapeRelation relation, java.time.ZoneId timeZone, DateMathParser parser, QueryShardContext context)
Factory method for range queries.org.apache.lucene.search.Query
regexpQuery(java.lang.String value, int flags, int maxDeterminizedStates, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, QueryShardContext context)
NamedAnalyzer
searchAnalyzer()
NamedAnalyzer
searchQuoteAnalyzer()
void
setBoost(float boost)
void
setEagerGlobalOrdinals(boolean eagerGlobalOrdinals)
void
setHasDocValues(boolean hasDocValues)
void
setIndexAnalyzer(NamedAnalyzer analyzer)
void
setMeta(java.util.Map<java.lang.String,java.lang.String> meta)
Associate metadata with this field.void
setName(java.lang.String name)
void
setNullValue(java.lang.Object nullValue)
Sets the null value and initializes the string versionvoid
setSearchAnalyzer(NamedAnalyzer analyzer)
void
setSearchQuoteAnalyzer(NamedAnalyzer analyzer)
void
setSimilarity(SimilarityProvider similarity)
SimilarityProvider
similarity()
org.apache.lucene.search.spans.SpanQuery
spanPrefixQuery(java.lang.String value, org.apache.lucene.search.spans.SpanMultiTermQueryWrapper.SpanRewriteMethod method, QueryShardContext context)
abstract org.apache.lucene.search.Query
termQuery(java.lang.Object value, QueryShardContext context)
Generates a query that will only match documents that contain the given value.org.apache.lucene.search.Query
termsQuery(java.util.List<?> values, QueryShardContext context)
Build a constant-scoring query that matches all values.abstract java.lang.String
typeName()
Returns the name of this type, as would be specified in mapping propertiesjava.lang.Object
valueForDisplay(java.lang.Object value)
Given a value that comes from the stored fields API, convert it to the expected type.org.apache.lucene.search.Query
wildcardQuery(java.lang.String value, org.apache.lucene.search.MultiTermQuery.RewriteMethod method, QueryShardContext context)
Methods inherited from class org.apache.lucene.document.FieldType
checkIfFrozen, docValuesType, freeze, getAttributes, indexOptions, omitNorms, pointDimensionCount, pointIndexDimensionCount, pointNumBytes, putAttribute, setDimensions, setDimensions, setDocValuesType, setIndexOptions, setOmitNorms, setStored, setStoreTermVectorOffsets, setStoreTermVectorPayloads, setStoreTermVectorPositions, setStoreTermVectors, setTokenized, stored, storeTermVectorOffsets, storeTermVectorPayloads, storeTermVectorPositions, storeTermVectors, tokenized, toString
-
Constructor Details
-
MappedFieldType
-
MappedFieldType
public MappedFieldType()
-
-
Method Details
-
clone
- Overrides:
clone
in classjava.lang.Object
-
fielddataBuilder
Return a fielddata builder for this field- Parameters:
fullyQualifiedIndexName
- the name of the index this field-data is build for- Throws:
java.lang.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)
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equals
in classorg.apache.lucene.document.FieldType
-
hashCode
public int hashCode()- Overrides:
hashCode
in classorg.apache.lucene.document.FieldType
-
typeName
public abstract java.lang.String typeName()Returns the name of this type, as would be specified in mapping properties -
checkCompatibility
Checks for any conflicts between this field type and other. If strict is true, all properties must be equal. Otherwise, only properties which must never change in an index are checked. -
name
public java.lang.String name() -
setName
public void setName(java.lang.String name) -
boost
public float boost() -
setBoost
public void setBoost(float boost) -
hasDocValues
public boolean hasDocValues() -
setHasDocValues
public void setHasDocValues(boolean hasDocValues) -
indexAnalyzer
-
setIndexAnalyzer
-
searchAnalyzer
-
setSearchAnalyzer
-
searchQuoteAnalyzer
-
setSearchQuoteAnalyzer
-
similarity
-
setSimilarity
-
nullValue
public java.lang.Object nullValue()Returns the value that should be added when JSON null is found, or null if no value should be added -
nullValueAsString
public java.lang.String nullValueAsString()Returns the null value stringified or null if there is no null value -
setNullValue
public void setNullValue(java.lang.Object nullValue)Sets the null value and initializes the string version -
valueForDisplay
public java.lang.Object valueForDisplay(java.lang.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. -
isAggregatable
public boolean isAggregatable()Returns true if the field is aggregatable. -
termQuery
public abstract org.apache.lucene.search.Query termQuery(java.lang.Object value, @Nullable QueryShardContext context)Generates a query that will only match documents that contain the given value. The default implementation returns aTermQuery
over the value bytes, boosted byboost()
.- Throws:
java.lang.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 typejava.lang.UnsupportedOperationException
- if the field is not searchable regardless of optionsQueryShardException
- if the field is not searchable regardless of options
-
termsQuery
public org.apache.lucene.search.Query termsQuery(java.util.List<?> values, @Nullable QueryShardContext 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.QueryShardContext)
. -
rangeQuery
public org.apache.lucene.search.Query rangeQuery(java.lang.Object lowerTerm, java.lang.Object upperTerm, boolean includeLower, boolean includeUpper, ShapeRelation relation, java.time.ZoneId timeZone, DateMathParser parser, QueryShardContext context)Factory method for range queries.- Parameters:
relation
- the relation, nulls should be interpreted like INTERSECTS
-
fuzzyQuery
public org.apache.lucene.search.Query fuzzyQuery(java.lang.Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions, QueryShardContext context) -
prefixQuery
public org.apache.lucene.search.Query prefixQuery(java.lang.String value, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod method, QueryShardContext context) -
wildcardQuery
public org.apache.lucene.search.Query wildcardQuery(java.lang.String value, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod method, QueryShardContext context) -
regexpQuery
public org.apache.lucene.search.Query regexpQuery(java.lang.String value, int flags, int maxDeterminizedStates, @Nullable org.apache.lucene.search.MultiTermQuery.RewriteMethod method, QueryShardContext context) -
existsQuery
-
phraseQuery
public org.apache.lucene.search.Query phraseQuery(org.apache.lucene.analysis.TokenStream stream, int slop, boolean enablePositionIncrements) throws java.io.IOException- Throws:
java.io.IOException
-
multiPhraseQuery
public org.apache.lucene.search.Query multiPhraseQuery(org.apache.lucene.analysis.TokenStream stream, int slop, boolean enablePositionIncrements) throws java.io.IOException- Throws:
java.io.IOException
-
phrasePrefixQuery
public org.apache.lucene.search.Query phrasePrefixQuery(org.apache.lucene.analysis.TokenStream stream, int slop, int maxExpansions) throws java.io.IOException- Throws:
java.io.IOException
-
spanPrefixQuery
public org.apache.lucene.search.spans.SpanQuery spanPrefixQuery(java.lang.String value, org.apache.lucene.search.spans.SpanMultiTermQueryWrapper.SpanRewriteMethod method, QueryShardContext context) -
intervals
public org.apache.lucene.queries.intervals.IntervalsSource intervals(java.lang.String query, int max_gaps, boolean ordered, NamedAnalyzer analyzer, boolean prefix) throws java.io.IOExceptionCreate anIntervalsSource
to be used for proximity queries- Throws:
java.io.IOException
-
isFieldWithinQuery
public MappedFieldType.Relation isFieldWithinQuery(org.apache.lucene.index.IndexReader reader, java.lang.Object from, java.lang.Object to, boolean includeLower, boolean includeUpper, java.time.ZoneId timeZone, DateMathParser dateMathParser, QueryRewriteContext context) throws java.io.IOExceptionReturn 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:
java.io.IOException
-
failIfNoDocValues
protected final void failIfNoDocValues()- Throws:
java.lang.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() -
setEagerGlobalOrdinals
public void setEagerGlobalOrdinals(boolean eagerGlobalOrdinals) -
docValueFormat
Return aDocValueFormat
that 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 aTerm
from a query created withtermQuery(java.lang.Object, org.elasticsearch.index.query.QueryShardContext)
by recursively removingBoostQuery
wrappers.- Throws:
java.lang.IllegalArgumentException
- if the wrapped query is not aTermQuery
-
meta
public java.util.Map<java.lang.String,java.lang.String> meta()Get the metadata associated with this field. -
setMeta
public void setMeta(java.util.Map<java.lang.String,java.lang.String> meta)Associate metadata with this field.
-