Class ContextMapping<T extends ToXContent>
- java.lang.Object
-
- org.elasticsearch.search.suggest.completion.context.ContextMapping<T>
-
- All Implemented Interfaces:
ToXContent,ToXContentFragment
- Direct Known Subclasses:
CategoryContextMapping,GeoContextMapping
public abstract class ContextMapping<T extends ToXContent> extends java.lang.Object implements ToXContentFragment
AContextMappingdefines criteria that can be used to filter and/or boost suggestions at query time forCompletionFieldMapper. 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-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFIELD_NAMEstatic java.lang.StringFIELD_TYPEprotected java.lang.Stringnameprotected ContextMapping.Typetype-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
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(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, XContentParser parser)Parses a set of index-time contexts.java.util.List<ContextMapping.InternalQueryContext>parseQueryContext(XContentParser parser)Parses query contexts for this mapperprotected abstract XContentBuildertoInnerXContent(XContentBuilder builder, 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()XContentBuildertoXContent(XContentBuilder builder, 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.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentFragment
isFragment
-
-
-
-
Field Detail
-
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
protected final ContextMapping.Type type
-
name
protected final java.lang.String name
-
-
Constructor Detail
-
ContextMapping
protected ContextMapping(ContextMapping.Type type, java.lang.String name)
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 Detail
-
type
public ContextMapping.Type 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, XContentParser parser) throws java.io.IOException, ElasticsearchParseException
Parses a set of index-time contexts.- Throws:
java.io.IOExceptionElasticsearchParseException
-
parseContext
protected abstract java.util.Set<java.lang.String> parseContext(ParseContext.Document document)
Retrieves a set of context from adocumentat index-time.
-
fromXContent
protected abstract T fromXContent(XContentParser context) throws java.io.IOException
Prototype for the query context- Throws:
java.io.IOException
-
parseQueryContext
public final java.util.List<ContextMapping.InternalQueryContext> parseQueryContext(XContentParser parser) throws java.io.IOException, ElasticsearchParseException
Parses 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 XContentBuilder toInnerXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
Implementations 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 XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
toXContentin interfaceToXContent- 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
-
-