here is my input
{"field_a":"value a 1","data":{"p_id":null,"id":"abc123"},"field_c":"value c 1"}
{"field_a":"value a 2","data":{"p_id":"123445","id":"abc456"},"field_c":"value c 2"}
here is my complete filebeat.yml which prints to console
filebeat.inputs:
# filestream is an input for collecting log messages from files.
- type: filestream
# Unique ID among all inputs, an ID is required.
id: my-filestream-id
# Change to true to enable this input configuration.
enabled: true
# Paths that should be crawled and fetched. Glob based paths.
paths:
- /Users/sbrown/workspace/sample-data/discuss/ndjson/sample-fingerprint.ndjson
filebeat.config.modules:
# Glob pattern for configuration loading
path: ${path.config}/modules.d/*.yml
# Set to true to enable config reloading
reload.enabled: false
# Period on which files under path should be checked for changes
#reload.period: 10s
# ======================= Elasticsearch template setting =======================
setup.template.settings:
index.number_of_shards: 1
#index.codec: best_compression
#_source.enabled: false
setup.kibana:
output.console:
codec.json:
pretty: true
# ---------------------------- Elasticsearch Output ----------------------------
# output.elasticsearch:
# # Array of hosts to connect to.
# hosts: ["localhost:9200"]
# Protocol - either `http` (default) or `https`.
#protocol: "https"
# Authentication credentials - either API key or username/password.
#api_key: "id:api_key"
#username: "elastic"
#password: "changeme"
# ================================= Processors =================================
processors:
- decode_json_fields:
fields: ["message"]
target: ""
- script:
lang: javascript
source: >
function process(event) {
var value = event.Get("data.p_id");
if (value !== null) {
event.Put("temp_id", value);
} else {
event.Put("temp_id", event.Get("data.id"));
}
}
- fingerprint:
fields: ["temp_id"]
target_field: "@metadata._id"
- add_fields:
target: "@metadata"
fields:
op_type: "index"
- drop_fields:
fields: ["temp_id"]
and the output
{
"@timestamp": "2023-03-01T02:43:27.611Z",
"@metadata": {
"beat": "filebeat",
"type": "_doc",
"version": "8.6.2",
"_id": "46cc154a58a4972595f8b43a8bc1af95fb42b4ba61e9522a4bf8954a64483875",
"op_type": "index"
},
"ecs": {
"version": "8.0.0"
},
"host": {
"name": "hyperion"
},
"agent": {
"ephemeral_id": "3a97c0a8-2409-4535-be85-42ffa8c7dd4a",
"id": "66df3886-486a-434b-bb8d-9f3035983f8d",
"name": "hyperion",
"type": "filebeat",
"version": "8.6.2"
},
"field_a": "value a 1",
"log": {
"offset": 0,
"file": {
"path": "/Users/sbrown/workspace/sample-data/discuss/ndjson/sample-fingerprint.ndjson"
}
},
"message": "{\"field_a\":\"value a 1\",\"data\":{\"p_id\":null,\"id\":\"abc123\"},\"field_c\":\"value c 1\"}",
"input": {
"type": "filestream"
},
"field_c": "value c 1",
"data": {
"p_id": null,
"id": "abc123"
}
}
{
"@timestamp": "2023-03-01T02:43:27.611Z",
"@metadata": {
"beat": "filebeat",
"type": "_doc",
"version": "8.6.2",
"_id": "378c48f4c86340e2e287b5731a3cbc9aab9657b8c8f872bdd82f4f9a8c30e194",
"op_type": "index"
},
"ecs": {
"version": "8.0.0"
},
"host": {
"name": "hyperion"
},
"agent": {
"version": "8.6.2",
"ephemeral_id": "3a97c0a8-2409-4535-be85-42ffa8c7dd4a",
"id": "66df3886-486a-434b-bb8d-9f3035983f8d",
"name": "hyperion",
"type": "filebeat"
},
"field_a": "value a 2",
"data": {
"p_id": "123445",
"id": "abc456"
},
"message": "{\"field_a\":\"value a 2\",\"data\":{\"p_id\":\"123445\",\"id\":\"abc456\"},\"field_c\":\"value c 2\"}",
"log": {
"offset": 81,
"file": {
"path": "/Users/sbrown/workspace/sample-data/discuss/ndjson/sample-fingerprint.ndjson"
}
},
"input": {
"type": "filestream"
},
"field_c": "value c 2"
}