I have a data entry through Logstash (8.9.1) that does not have a field (hostname) only ip.
I created a pipeline using the Elastic API (8.9.1) like this:
PUT _ingest/pipeline/name_device_ping
{
"processors": [
{
"script": {
"source": """
if (ctx.ip == '192.168.203.1') {
ctx.hostname = 'SWITCH-CORE';
}
""",
"lang": "painless"
}
}
],
"on_failure": [
{
"append": {
"field": "meta.errors",
"value": "{{ _ingest.on_failure_message }}, {{ _ingest.on_failure_processor_type }}, {{ _ingest.on_failure_processor_tag }}"
}
},
{
"set": {
"field": "_index",
"value": "failed-{{ _index }}"
}
}
]
}
When executed it returns true.
When simulating:
{
"docs": [
{
"doc": {
"_index": "_index",
"_id": "_id",
"_version": "-3",
"_source": {
"loss": 0,
"hostname": "SWITCH-CORE",
"@timestamp": "2023-10-06T09:30:52-03:00",
"jitter": 0,
"ip": "192.168.203.1",
"latency": 2,
"error": ""
},
"_ingest": {
"timestamp": "2023-10-06T15:19:01.551366204Z"
}
}
}
]
}
Apparently the hostname field was created successfully.
However, when checking when entering new data, the field is always empty.
I don't know which part I missed something.