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
ConstructorsModifierConstructorDescriptionprotectedDocumentParserContext(MappingLookup mappingLookup, MappingParserContext mappingParserContext, SourceToParse source, ObjectMapper parent, ObjectMapper.Dynamic dynamic) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidaddDoc(LuceneDocument doc) final booleanaddDynamicMapper(Mapper mapper) Add a new mapper dynamically created while parsing.final voidaddIgnoredField(String field) Add the givenfieldto the set of ignored fields.final voidAdd the given ignored values to the corresponding list.final DocumentParserContextaddIgnoredFieldFromContext(IgnoredSourceFieldMapper.NameValue ignoredFieldWithNoSource) Adds an ignored field from the parser context, capturing an object or an array.final voidaddToFieldNames(String field) Add the givenfieldto the _field_names field Use this if an exists query run against the field cannot use docvalues or norms.final booleanfinal DocumentParserContextcreateChildContext(ObjectMapper parent) final DocumentParserContextcreateCopyToContext(String copyToField, LuceneDocument doc) Return a context for copy_to directivesfinal MapperBuilderContextCreates a context to build dynamic mappersfinal DocumentParserContextcreateFlattenContext(String fieldName) Return a context for flattening subobjectsfinal DocumentParserContextcreateNestedContext(NestedObjectMapper nestedMapper) Return a new context that will be used within a nested document.abstract LuceneDocumentdoc()final StringDescription on the document being parsed used in error messages.dynamic()final MappingParserContextdynamicTemplateParserContext(DateFormatter dateFormatter) final DynamicTemplatefindDynamicTemplate(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 ofMappers associated with a field name that will need to be added to their respective parentObjectMappers 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 MetadataFieldMappergetMetadataMapper(String mapperName) The collection of dimensions for this document.final booleanfinal booleanfinal Stringid()final voidfinal IndexAnalyzersfinal IndexSettingsbooleanbooleanbooleanfinal MappingLookupvoidmarkFieldAsAppliedFromTemplate(String fieldName) voidmarkFieldAsCopyTo(String fieldName) final DocumentParserContextmaybeCloneForArray(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 ObjectMapperparent()abstract XContentParserparser()abstract ContentPathpath()final RootObjectMapperroot()abstract LuceneDocumentrootDoc()final Stringrouting()seqID()final SourceToParsefinal DocumentParserContextswitchDoc(LuceneDocument document) Return a new context that has the provided document as the current document.final DocumentParserContextswitchParser(XContentParser parser) Clone this context, replacing the XContentParser with the passed onevoidupdateDynamicMappers(String name, List<Mapper> mappers) final RootObjectMapper.Builderfinal org.apache.lucene.document.Fieldversion()final voidversion(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 givenfieldto 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 currentDocumentParserContextand 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 givenfieldto 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
trueif the mapper could be created,falseif 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.TRUEorObjectMapper.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 allMappers that will need to be added to their respective parentObjectMappers in order to become part of the resulting dynamic mapping update. -
getDynamicMappers
Returns the dynamic Consists of a flat set ofMappers associated with a field name that will need to be added to their respective parentObjectMappers 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 ofRuntimeFields. Runtime fields get dynamically mapped whenObjectMapper.Dynamic.RUNTIMEis used, or when dynamic templates specify aruntimesection. -
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.
-