Class ContextMapping<T extends org.elasticsearch.common.xcontent.ToXContent>
java.lang.Object
org.elasticsearch.search.suggest.completion.context.ContextMapping<T>
- All Implemented Interfaces:
org.elasticsearch.common.xcontent.ToXContent,org.elasticsearch.common.xcontent.ToXContentFragment
- Direct Known Subclasses:
CategoryContextMapping,GeoContextMapping
public abstract class ContextMapping<T extends org.elasticsearch.common.xcontent.ToXContent>
extends java.lang.Object
implements org.elasticsearch.common.xcontent.ToXContentFragment
A
ContextMapping defines criteria that can be used to
filter and/or boost suggestions at query time for CompletionFieldMapper.
Implementations have to define how contexts are parsed at query/index time-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classContextMapping.InternalQueryContextstatic classContextMapping.Type -
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFIELD_NAMEstatic java.lang.StringFIELD_TYPEprotected java.lang.Stringnameprotected ContextMapping.Typetype -
Constructor Summary
Constructors Modifier Constructor Description protectedContextMapping(ContextMapping.Type type, java.lang.String name)Define a new context mapping of a specific type -
Method Summary
Modifier and Type Method Description booleanequals(java.lang.Object o)protected abstract TfromXContent(org.elasticsearch.common.xcontent.XContentParser context)Prototype for the query contextinthashCode()java.lang.Stringname()protected abstract java.util.Set<java.lang.String>parseContext(ParseContext.Document document)Retrieves a set of context from adocumentat index-time.abstract java.util.Set<java.lang.String>parseContext(ParseContext parseContext, org.elasticsearch.common.xcontent.XContentParser parser)Parses a set of index-time contexts.java.util.List<ContextMapping.InternalQueryContext>parseQueryContext(org.elasticsearch.common.xcontent.XContentParser parser)Parses query contexts for this mapperprotected abstract org.elasticsearch.common.xcontent.XContentBuildertoInnerXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)Implementations should add specific configurations that need to be persistedprotected abstract java.util.List<ContextMapping.InternalQueryContext>toInternalQueryContexts(java.util.List<T> queryContexts)Convert query contexts to common representationjava.lang.StringtoString()org.elasticsearch.common.xcontent.XContentBuildertoXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)ContextMapping.Typetype()static voidvalidateContextPaths(Version indexVersionCreated, java.util.List<FieldMapper> fieldMappers, java.util.function.Function<java.lang.String,MappedFieldType> fieldResolver)Verifies that all field paths specified in contexts point to the fields with correct mappingsprotected voidvalidateReferences(Version indexVersionCreated, java.util.function.Function<java.lang.String,MappedFieldType> fieldResolver)Checks if the current context is consistent with the rest of the fields.
-
Field Details
-
FIELD_TYPE
public static final java.lang.String FIELD_TYPE- See Also:
- Constant Field Values
-
FIELD_NAME
public static final java.lang.String FIELD_NAME- See Also:
- Constant Field Values
-
type
-
name
protected final java.lang.String name
-
-
Constructor Details
-
ContextMapping
Define a new context mapping of a specific type- Parameters:
type- type of context mapping, eitherContextMapping.Type.CATEGORYorContextMapping.Type.GEOname- name of context mapping
-
-
Method Details
-
type
- Returns:
- the type name of the context
-
name
public java.lang.String name()- Returns:
- the name/id of the context
-
parseContext
public abstract java.util.Set<java.lang.String> parseContext(ParseContext parseContext, org.elasticsearch.common.xcontent.XContentParser parser) throws java.io.IOException, ElasticsearchParseExceptionParses a set of index-time contexts.- Throws:
java.io.IOExceptionElasticsearchParseException
-
parseContext
Retrieves a set of context from adocumentat index-time. -
fromXContent
protected abstract T fromXContent(org.elasticsearch.common.xcontent.XContentParser context) throws java.io.IOExceptionPrototype for the query context- Throws:
java.io.IOException
-
parseQueryContext
public final java.util.List<ContextMapping.InternalQueryContext> parseQueryContext(org.elasticsearch.common.xcontent.XContentParser parser) throws java.io.IOException, ElasticsearchParseExceptionParses query contexts for this mapper- Throws:
java.io.IOExceptionElasticsearchParseException
-
toInternalQueryContexts
protected abstract java.util.List<ContextMapping.InternalQueryContext> toInternalQueryContexts(java.util.List<T> queryContexts)Convert query contexts to common representation -
toInnerXContent
protected abstract org.elasticsearch.common.xcontent.XContentBuilder toInnerXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws java.io.IOExceptionImplementations should add specific configurations that need to be persisted- Throws:
java.io.IOException
-
validateReferences
protected void validateReferences(Version indexVersionCreated, java.util.function.Function<java.lang.String,MappedFieldType> fieldResolver)Checks if the current context is consistent with the rest of the fields. For example, the GeoContext should check that the field that it points to has the correct type. -
validateContextPaths
public static void validateContextPaths(Version indexVersionCreated, java.util.List<FieldMapper> fieldMappers, java.util.function.Function<java.lang.String,MappedFieldType> fieldResolver)Verifies that all field paths specified in contexts point to the fields with correct mappings -
toXContent
public final org.elasticsearch.common.xcontent.XContentBuilder toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws java.io.IOException- Specified by:
toXContentin interfaceorg.elasticsearch.common.xcontent.ToXContent- Throws:
java.io.IOException
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-