java.lang.Object
org.elasticsearch.index.mapper.DocumentParserContext
Context used when parsing incoming documents. Holds everything that is needed to parse a document as well as
the lucene data structures and mappings to be dynamically created as the outcome of parsing a document.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
DocumentParserContext
(MappingLookup mappingLookup, MappingParserContext mappingParserContext, SourceToParse source, ObjectMapper parent, ObjectMapper.Dynamic dynamic) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
addDoc
(LuceneDocument doc) final boolean
addDynamicMapper
(Mapper mapper) Add a new mapper dynamically created while parsing.final void
addIgnoredField
(String field) Add the givenfield
to the set of ignored fields.final void
Add the given ignored values to the corresponding list.final DocumentParserContext
addIgnoredFieldFromContext
(IgnoredSourceFieldMapper.NameValue ignoredFieldWithNoSource) Adds an ignored field from the parser context, capturing an object or an array.final void
addToFieldNames
(String field) Add the givenfield
to the _field_names field Use this if an exists query run against the field cannot use docvalues or norms.final boolean
final DocumentParserContext
createChildContext
(ObjectMapper parent) final DocumentParserContext
createCopyToContext
(String copyToField, LuceneDocument doc) Return a context for copy_to directivesfinal MapperBuilderContext
Creates a context to build dynamic mappersfinal DocumentParserContext
createFlattenContext
(String fieldName) Return a context for flattening subobjectsfinal DocumentParserContext
createNestedContext
(NestedObjectMapper nestedMapper) Return a new context that will be used within a nested document.abstract LuceneDocument
doc()
final String
Description on the document being parsed used in error messages.dynamic()
final MappingParserContext
dynamicTemplateParserContext
(DateFormatter dateFormatter) final DynamicTemplate
findDynamicTemplate
(String fieldName, DynamicTemplate.XContentFieldType matchType) Find a dynamic mapping template for the given field and its matching typeGet dynamic mappers created as a result of parsing an incoming document.getDynamicMappers
(String fieldName) Returns the dynamic Consists of a flat set ofMapper
s associated with a field name that will need to be added to their respective parentObjectMapper
s in order to become part of the resulting dynamic mapping update.final List
<RuntimeField> Get dynamic runtime fields created while parsing.final Collection
<String> Return the collection of fields that have been ignored so far.Return the collection of values for fields that have been ignored so far.final MetadataFieldMapper
getMetadataMapper
(String mapperName) The collection of dimensions for this document.final boolean
final boolean
final String
id()
final void
final IndexAnalyzers
final IndexSettings
boolean
boolean
boolean
final MappingLookup
void
markFieldAsAppliedFromTemplate
(String fieldName) void
markFieldAsCopyTo
(String fieldName) final DocumentParserContext
maybeCloneForArray
(Mapper mapper) Clones the current context to mark it as an array, if it's not already marked, or restore it if it's within a nested object.abstract Iterable
<LuceneDocument> Returns an Iterable over all non-root documents.final ObjectMapper
parent()
abstract XContentParser
parser()
abstract ContentPath
path()
final RootObjectMapper
root()
abstract LuceneDocument
rootDoc()
final String
routing()
seqID()
final SourceToParse
final DocumentParserContext
switchDoc
(LuceneDocument document) Return a new context that has the provided document as the current document.final DocumentParserContext
switchParser
(XContentParser parser) Clone this context, replacing the XContentParser with the passed onevoid
updateDynamicMappers
(String name, List<Mapper> mappers) final RootObjectMapper.Builder
final org.apache.lucene.document.Field
version()
final void
version
(org.apache.lucene.document.Field version)
-
Constructor Details
-
DocumentParserContext
protected DocumentParserContext(MappingLookup mappingLookup, MappingParserContext mappingParserContext, SourceToParse source, ObjectMapper parent, ObjectMapper.Dynamic dynamic)
-
-
Method Details
-
indexSettings
-
indexAnalyzers
-
root
-
parent
-
mappingLookup
-
getMetadataMapper
-
dynamicTemplateParserContext
-
sourceToParse
-
routing
-
addIgnoredField
Add the givenfield
to the set of ignored fields. -
getIgnoredFields
Return the collection of fields that have been ignored so far. -
addIgnoredField
Add the given ignored values to the corresponding list. -
getIgnoredFieldValues
Return the collection of values for fields that have been ignored so far. -
addIgnoredFieldFromContext
public final DocumentParserContext addIgnoredFieldFromContext(IgnoredSourceFieldMapper.NameValue ignoredFieldWithNoSource) throws IOException Adds an ignored field from the parser context, capturing an object or an array. In case of nested arrays, i.e. capturing an array within an array, elements tracked as ignored fields may interfere with the rest, as ignored source contents take precedence over regular field contents with the same leaf name. To prevent missing array elements from synthetic source, all array elements get recorded in ignored source. Otherwise, just the value in the current parsing context gets captured. In both cases, a new parser sub-context gets created from the currentDocumentParserContext
and returned, indicating that the source for the sub-context has been captured, to avoid double-storing parts of its contents to ignored source.- Throws:
IOException
-
maybeCloneForArray
Clones the current context to mark it as an array, if it's not already marked, or restore it if it's within a nested object. Applies to synthetic source only.- Throws:
IOException
-
addToFieldNames
Add the givenfield
to the _field_names field Use this if an exists query run against the field cannot use docvalues or norms. -
version
public final org.apache.lucene.document.Field version() -
version
public final void version(org.apache.lucene.document.Field version) -
id
-
id
-
seqID
-
canAddIgnoredField
public final boolean canAddIgnoredField() -
documentDescription
Description on the document being parsed used in error messages. Not called unless there is an error. -
getMapper
-
dynamic
-
markFieldAsAppliedFromTemplate
-
isFieldAppliedFromTemplate
-
markFieldAsCopyTo
-
isCopyToDestinationField
-
addDynamicMapper
Add a new mapper dynamically created while parsing.- Returns:
- returns
true
if the mapper could be created,false
if the dynamic mapper has been ignored due to the field limit - Throws:
IllegalArgumentException
- if the field limit has been exceeded. This can happen when dynamic is set toObjectMapper.Dynamic.TRUE
orObjectMapper.Dynamic.RUNTIME
.
-
hasDynamicMappersOrRuntimeFields
public final boolean hasDynamicMappersOrRuntimeFields()- Returns:
- true if either
getDynamicMappers()
orgetDynamicRuntimeFields()
will return a non-empty result
-
hasDynamicMappers
public final boolean hasDynamicMappers()- Returns:
- true if either
getDynamicMappers()
will return a non-empty mapper list
-
getDynamicMappers
Get dynamic mappers created as a result of parsing an incoming document. Responsible for exposing all the newly created fields that need to be merged into the existing mappings. Used to create the required mapping update at the end of document parsing. Consists of a allMapper
s that will need to be added to their respective parentObjectMapper
s in order to become part of the resulting dynamic mapping update. -
getDynamicMappers
Returns the dynamic Consists of a flat set ofMapper
s associated with a field name that will need to be added to their respective parentObjectMapper
s in order to become part of the resulting dynamic mapping update.- Parameters:
fieldName
- Full field name with dot-notation.- Returns:
- List of Mappers or null
-
updateDynamicMappers
-
getDynamicRuntimeFields
Get dynamic runtime fields created while parsing. Holds a flat set ofRuntimeField
s. Runtime fields get dynamically mapped whenObjectMapper.Dynamic.RUNTIME
is used, or when dynamic templates specify aruntime
section. -
nonRootDocuments
Returns an Iterable over all non-root documents. If there are no non-root documents the iterable will return an empty iterator. -
updateRoot
- Returns:
- a RootObjectMapper.Builder to be used to construct a dynamic mapping update
-
isWithinCopyTo
public boolean isWithinCopyTo() -
createChildContext
-
createNestedContext
Return a new context that will be used within a nested document. -
switchDoc
Return a new context that has the provided document as the current document. -
createCopyToContext
public final DocumentParserContext createCopyToContext(String copyToField, LuceneDocument doc) throws IOException Return a context for copy_to directives- Parameters:
copyToField
- the name of the field to copy todoc
- the document to target- Throws:
IOException
-
createFlattenContext
Return a context for flattening subobjects- Parameters:
fieldName
- the name of the field to be flattened
-
switchParser
Clone this context, replacing the XContentParser with the passed one- Parameters:
parser
- the replacement parser- Returns:
- a new context with a replaced parser
-
getRoutingFields
The collection of dimensions for this document. -
path
-
createDynamicMapperBuilderContext
Creates a context to build dynamic mappers -
parser
-
rootDoc
-
doc
-
addDoc
-
findDynamicTemplate
public final DynamicTemplate findDynamicTemplate(String fieldName, DynamicTemplate.XContentFieldType matchType) Find a dynamic mapping template for the given field and its matching type- Parameters:
fieldName
- the name of the fieldmatchType
- the expecting matchType of the field- Returns:
- the matching template; otherwise returns null
- Throws:
DocumentParsingException
- if the given field has a dynamic template name specified, but no template matches that name.
-