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
AContextMapping
defines 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 class
ContextMapping.InternalQueryContext
static class
ContextMapping.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.String
FIELD_NAME
static java.lang.String
FIELD_TYPE
protected java.lang.String
name
protected ContextMapping.Type
type
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ContextMapping(ContextMapping.Type type, java.lang.String name)
Define a new context mapping of a specific type
-
Method Summary
Modifier and Type Method Description boolean
equals(java.lang.Object o)
protected abstract T
fromXContent(XContentParser context)
Prototype for the query contextint
hashCode()
java.lang.String
name()
protected abstract java.util.Set<java.lang.String>
parseContext(ParseContext.Document document)
Retrieves a set of context from adocument
at 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 XContentBuilder
toInnerXContent(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.String
toString()
XContentBuilder
toXContent(XContentBuilder builder, ToXContent.Params params)
ContextMapping.Type
type()
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 mappingsprotected 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.-
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.CATEGORY
orContextMapping.Type.GEO
name
- 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.IOException
ElasticsearchParseException
-
parseContext
protected abstract java.util.Set<java.lang.String> parseContext(ParseContext.Document document)
Retrieves a set of context from adocument
at 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.IOException
ElasticsearchParseException
-
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:
toXContent
in interfaceToXContent
- Throws:
java.io.IOException
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-