KV processor

The kv processor automatically extracts specific event fields or messages that are in a key=value format. This structured format organizes your data by grouping it together based on keys and values. It’s helpful for analyzing, visualizing, and using data, such as user behavior analytics, performance optimizations, or security investigations.

Example

The following is the syntax for the kv processor:

  1. {
  2. "kv": {
  3. "field": "message",
  4. "field_split": " ",
  5. "value_split": " "
  6. }
  7. }

copy

Configuration parameters

The following table lists the required and optional parameters for the kv processor.

ParameterRequired/OptionalDescription
fieldRequiredThe name of the field containing the data to be parsed. Supports template snippets.
field_splitRequiredThe regex pattern for key-value pair splitting.
value_splitRequiredThe regex pattern for splitting the key from the value within a key-value pair, for example, equal sign = or colon :.
exclude_keysOptionalThe keys to exclude from the document. Default is null.
include_keysOptionalThe keys for filtering and inserting. Default is to include all keys.
prefixOptionalThe prefix to add to the extracted keys. Default is null.
strip_bracketsOptionalIf set to true, strips brackets ((), <>, or []) and quotes ( or ) from extracted values. Default is false.
trim_keyOptionalThe string of characters to trim from the extracted keys.
trim valueOptionalThe string of characters to trim from the extracted values.
descriptionOptionalA brief description of the processor.
ifOptionalA condition for running the processor.
ignore_failureOptionalIf set to true, failures are ignored. Default is false.
on_failureOptionalA list of processors to run if the processor fails.
ignore_missingOptionalSpecifies whether the processor should ignore documents that do not contain the specified field. Default is false.
tagOptionalAn identifier tag for the processor. Useful for debugging in order to distinguish between processors of the same type.
target_fieldOptionalThe name of the field in which to insert the extracted keys. Default is null. Supports template snippets.

Using the processor

Follow these steps to use the processor in a pipeline.

Step 1: Create a pipeline

The following query creates a pipeline, named kv-pipeline, that uses the kv processor to extract the message field of a document:

  1. PUT _ingest/pipeline/kv-pipeline
  2. {
  3. "description" : "Pipeline that extracts user profile data",
  4. "processors" : [
  5. {
  6. "kv" : {
  7. "field" : "message",
  8. "field_split": " ",
  9. "value_split": "="
  10. }
  11. }
  12. ]
  13. }

copy

Step 2 (Optional): Test the pipeline

It is recommended that you test your pipeline before you ingest documents.

To test the pipeline, run the following query:

  1. POST _ingest/pipeline/kv-pipeline/_simulate
  2. ```json
  3. {
  4. "docs": [
  5. {
  6. "_index": "testindex1",
  7. "_id": "1",
  8. "_source":{
  9. "message": "goodbye=everybody hello=world"
  10. }
  11. }
  12. ]
  13. }

copy

Response

The following example response confirms that the pipeline is working as expected:

  1. {
  2. "docs": [
  3. {
  4. "doc": {
  5. "_index": "testindex1",
  6. "_id": "1",
  7. "_source": {
  8. "hello": "world",
  9. "message": "goodbye=everybody hello=world",
  10. "goodbye": "everybody"
  11. },
  12. "_ingest": {
  13. "timestamp": "2023-12-06T09:59:21.823292Z"
  14. }
  15. }
  16. }
  17. ]
  18. }

Step 3: Ingest a document

The following query ingests a document into an index named testindex1:

  1. PUT testindex1/_doc/1?pipeline=kv-pipeline
  2. ```json
  3. {
  4. "message": "goodbye=everybody hello=world"
  5. }

copy

Step 4 (Optional): Retrieve the document

To retrieve the document, run the following query:

  1. GET testindex1/_doc/1

copy