java.lang.Object
org.elasticsearch.ingest.IngestDocument
Represents a single document being captured before indexing and holds the source and metadata (like id, type and index).
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionIngestDocument
(String index, String id, long version, String routing, VersionType versionType, Map<String, Object> source) Constructor to create an IngestDocument from its constituent maps.IngestDocument
(IngestDocument other) Copy constructor that creates a newIngestDocument
which has exactly the same properties as the one provided. -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendFieldValue
(String path, Object value) Appends the provided value to the provided path in the document.void
appendFieldValue
(String path, Object value, boolean allowDuplicates) Appends the provided value to the provided path in the document.void
appendFieldValue
(TemplateScript.Factory fieldPathTemplate, ValueSource valueSource, boolean allowDuplicates) Appends the provided value to the provided path in the document.static Object
static <K,
V> Map<K, V> deepCopyMap
(Map<K, V> source) boolean
void
doNoSelfReferencesCheck
(boolean doNoSelfReferencesCheck) Whether the ingest framework should perform a self referencing check after this ingest document has been processed by all pipelines.boolean
void
executePipeline
(Pipeline pipeline, BiConsumer<IngestDocument, Exception> handler) Executes the given pipeline with for this document unless the pipeline has already been executed for this document.getAllFields
(Map<String, Object> input) CtxMap<?>
Get the CtxMap<T> T
getFieldValue
(String path, Class<T> clazz) Returns the value contained in the document for the provided path<T> T
getFieldValue
(String path, Class<T> clazz, boolean ignoreMissing) Returns the value contained in the document for the provided path<T> T
getFieldValue
(TemplateScript.Factory pathTemplate, Class<T> clazz) Returns the value contained in the document with the provided templated pathbyte[]
getFieldValueAsBytes
(String path) Returns the value contained in the document for the provided path as a byte array.byte[]
getFieldValueAsBytes
(String path, boolean ignoreMissing) Returns the value contained in the document for the provided path as a byte array.Returns the available ingest metadata fields, by default only timestamp, but it is possible to set additional ones.Get the strongly typed metadataGet all source values in a MapGet source and metadata mapboolean
Checks whether the document contains a value for the provided pathboolean
Checks whether the document contains a value for the provided pathboolean
hasField
(TemplateScript.Factory fieldPathTemplate) Checks whether the document contains a value for the provided templated pathint
hashCode()
void
removeField
(String path) Removes the field identified by the provided path.void
removeField
(TemplateScript.Factory fieldPathTemplate) Removes the field identified by the provided path.renderTemplate
(TemplateScript.Factory template) void
void
setFieldValue
(String path, Object value) Sets the provided value to the provided path in the document.void
setFieldValue
(TemplateScript.Factory fieldPathTemplate, Object value, boolean ignoreEmptyValue) Sets the provided value to the provided path in the document.void
setFieldValue
(TemplateScript.Factory fieldPathTemplate, ValueSource valueSource) Sets the provided value to the provided path in the document.void
setFieldValue
(TemplateScript.Factory fieldPathTemplate, ValueSource valueSource, boolean ignoreEmptyValue) Sets the provided value to the provided path in the document.toString()
boolean
updateIndexHistory
(String index) Adds an index to the index history for this document, returning true if the index was added to the index history (i.e.
-
Field Details
-
INGEST_KEY
- See Also:
-
SOURCE_KEY
- See Also:
-
PIPELINE_CYCLE_ERROR_MESSAGE
- See Also:
-
-
Constructor Details
-
IngestDocument
-
IngestDocument
Copy constructor that creates a newIngestDocument
which has exactly the same properties as the one provided. -
IngestDocument
Constructor to create an IngestDocument from its constituent maps. The maps are shallow copied.
-
-
Method Details
-
getFieldValue
Returns the value contained in the document for the provided path- Parameters:
path
- The path within the document in dot-notationclazz
- The expected class of the field value- Returns:
- the value for the provided path if existing
- Throws:
IllegalArgumentException
- if the path is null, empty, invalid, if the field doesn't exist or if the field that is found at the provided path is not of the expected type.
-
getFieldValue
Returns the value contained in the document for the provided path- Parameters:
path
- The path within the document in dot-notationclazz
- The expected class of the field valueignoreMissing
- The flag to determine whether to throw an exception when `path` is not found in the document.- Returns:
- the value for the provided path if existing, null otherwise.
- Throws:
IllegalArgumentException
- only if ignoreMissing is false and the path is null, empty, invalid, if the field doesn't exist or if the field that is found at the provided path is not of the expected type.
-
getFieldValue
Returns the value contained in the document with the provided templated path- Parameters:
pathTemplate
- The path within the document in dot-notationclazz
- The expected class of the field value- Returns:
- the value for the provided path if existing, null otherwise
- Throws:
IllegalArgumentException
- if the pathTemplate is null, empty, invalid, if the field doesn't exist, or if the field that is found at the provided path is not of the expected type.
-
getFieldValueAsBytes
Returns the value contained in the document for the provided path as a byte array. If the path value is a string, a base64 decode operation will happen. If the path value is a byte array, it is just returned- Parameters:
path
- The path within the document in dot-notation- Returns:
- the byte array for the provided path if existing
- Throws:
IllegalArgumentException
- if the path is null, empty, invalid, if the field doesn't exist or if the field that is found at the provided path is not of the expected type.
-
getFieldValueAsBytes
Returns the value contained in the document for the provided path as a byte array. If the path value is a string, a base64 decode operation will happen. If the path value is a byte array, it is just returned- Parameters:
path
- The path within the document in dot-notationignoreMissing
- The flag to determine whether to throw an exception when `path` is not found in the document.- Returns:
- the byte array for the provided path if existing
- Throws:
IllegalArgumentException
- if the path is null, empty, invalid, if the field doesn't exist or if the field that is found at the provided path is not of the expected type.
-
hasField
Checks whether the document contains a value for the provided templated path- Parameters:
fieldPathTemplate
- the template for the path within the document in dot-notation- Returns:
- true if the document contains a value for the field, false otherwise
- Throws:
IllegalArgumentException
- if the path is null, empty or invalid
-
hasField
Checks whether the document contains a value for the provided path- Parameters:
path
- The path within the document in dot-notation- Returns:
- true if the document contains a value for the field, false otherwise
- Throws:
IllegalArgumentException
- if the path is null, empty or invalid.
-
hasField
Checks whether the document contains a value for the provided path- Parameters:
path
- The path within the document in dot-notationfailOutOfRange
- Whether to throw an IllegalArgumentException if array is accessed outside of its range- Returns:
- true if the document contains a value for the field, false otherwise
- Throws:
IllegalArgumentException
- if the path is null, empty or invalid.
-
removeField
Removes the field identified by the provided path.- Parameters:
fieldPathTemplate
- Resolves to the path with dot-notation within the document- Throws:
IllegalArgumentException
- if the path is null, empty, invalid or if the field doesn't exist.
-
removeField
Removes the field identified by the provided path.- Parameters:
path
- the path of the field to be removed- Throws:
IllegalArgumentException
- if the path is null, empty, invalid or if the field doesn't exist.
-
appendFieldValue
Appends the provided value to the provided path in the document. Any non existing path element will be created. If the path identifies a list, the value will be appended to the existing list. If the path identifies a scalar, the scalar will be converted to a list and the provided value will be added to the newly created list. Supports multiple values too provided in forms of list, in that case all the values will be appended to the existing (or newly created) list.- Parameters:
path
- The path within the document in dot-notationvalue
- The value or values to append to the existing ones- Throws:
IllegalArgumentException
- if the path is null, empty or invalid.
-
appendFieldValue
Appends the provided value to the provided path in the document. Any non existing path element will be created. If the path identifies a list, the value will be appended to the existing list. If the path identifies a scalar, the scalar will be converted to a list and the provided value will be added to the newly created list. Supports multiple values too provided in forms of list, in that case all the values will be appended to the existing (or newly created) list.- Parameters:
path
- The path within the document in dot-notationvalue
- The value or values to append to the existing onesallowDuplicates
- When false, any values that already exist in the field will not be added- Throws:
IllegalArgumentException
- if the path is null, empty or invalid.
-
appendFieldValue
public void appendFieldValue(TemplateScript.Factory fieldPathTemplate, ValueSource valueSource, boolean allowDuplicates) Appends the provided value to the provided path in the document. Any non existing path element will be created. If the path identifies a list, the value will be appended to the existing list. If the path identifies a scalar, the scalar will be converted to a list and the provided value will be added to the newly created list. Supports multiple values too provided in forms of list, in that case all the values will be appended to the existing (or newly created) list.- Parameters:
fieldPathTemplate
- Resolves to the path with dot-notation within the documentvalueSource
- The value source that will produce the value or values to append to the existing onesallowDuplicates
- When false, any values that already exist in the field will not be added- Throws:
IllegalArgumentException
- if the path is null, empty or invalid.
-
setFieldValue
Sets the provided value to the provided path in the document. Any non existing path element will be created. If the last item in the path is a list, the value will replace the existing list as a whole. UseappendFieldValue(String, Object)
to append values to lists instead.- Parameters:
path
- The path within the document in dot-notationvalue
- The value to put in for the path key- Throws:
IllegalArgumentException
- if the path is null, empty, invalid or if the value cannot be set to the item identified by the provided path.
-
setFieldValue
Sets the provided value to the provided path in the document. Any non existing path element will be created. If the last element is a list, the value will replace the existing list.- Parameters:
fieldPathTemplate
- Resolves to the path with dot-notation within the documentvalueSource
- The value source that will produce the value to put in for the path key- Throws:
IllegalArgumentException
- if the path is null, empty, invalid or if the value cannot be set to the item identified by the provided path.
-
setFieldValue
public void setFieldValue(TemplateScript.Factory fieldPathTemplate, ValueSource valueSource, boolean ignoreEmptyValue) Sets the provided value to the provided path in the document. Any non existing path element will be created. If the last element is a list, the value will replace the existing list.- Parameters:
fieldPathTemplate
- Resolves to the path with dot-notation within the documentvalueSource
- The value source that will produce the value to put in for the path keyignoreEmptyValue
- The flag to determine whether to exit quietly when the value produced by TemplatedValue is null or empty- Throws:
IllegalArgumentException
- if the path is null, empty, invalid or if the value cannot be set to the item identified by the provided path.
-
setFieldValue
public void setFieldValue(TemplateScript.Factory fieldPathTemplate, Object value, boolean ignoreEmptyValue) Sets the provided value to the provided path in the document. Any non existing path element will be created. If the last element is a list, the value will replace the existing list.- Parameters:
fieldPathTemplate
- Resolves to the path with dot-notation within the documentvalue
- The value to put in for the path keyignoreEmptyValue
- The flag to determine whether to exit quietly when the value produced by TemplatedValue is null or empty- Throws:
IllegalArgumentException
- if the path is null, empty, invalid or if the value cannot be set to the item identified by the provided path.
-
renderTemplate
-
getSourceAndMetadata
Get source and metadata map -
getCtxMap
Get the CtxMap -
getMetadata
Get the strongly typed metadata -
getSource
Get all source values in a Map -
getIngestMetadata
Returns the available ingest metadata fields, by default only timestamp, but it is possible to set additional ones. Use only for reading values, modify them instead usingsetFieldValue(String, Object)
andremoveField(String)
-
deepCopyMap
-
deepCopy
-
getAllFields
-
executePipeline
Executes the given pipeline with for this document unless the pipeline has already been executed for this document.- Parameters:
pipeline
- the pipeline to executehandler
- handles the result or failure
-
updateIndexHistory
Adds an index to the index history for this document, returning true if the index was added to the index history (i.e. if it wasn't already in the index history).- Parameters:
index
- the index to potentially add to the index history- Returns:
- true if the index history did not already contain the index in question
-
getIndexHistory
- Returns:
- an unmodifiable view of the document's index history
-
doNoSelfReferencesCheck
public boolean doNoSelfReferencesCheck()- Returns:
- Whether a self referencing check should be performed
-
doNoSelfReferencesCheck
public void doNoSelfReferencesCheck(boolean doNoSelfReferencesCheck) Whether the ingest framework should perform a self referencing check after this ingest document has been processed by all pipelines. Doing this check adds an extra tax to ingest and should only be performed when really needed. Only if a processor is executed that could add self referencing maps or lists then this check must be performed. Most processors will not be able to do this, hence the default isfalse
.- Parameters:
doNoSelfReferencesCheck
- Whether a self referencing check should be performed
-
equals
-
hashCode
public int hashCode() -
toString
-
reroute
-