-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace function does not working propertly #20988
Labels
type: bug
A code related bug.
Comments
Jerrimikkihvatai
changed the title
replace function do not working propertly
replace function does not working propertly
Aug 2, 2024
Hi, you need to use # vector.toml
[sources.my_source]
type = "file"
include = ["/etc/vector/x.log"]
[transforms.parse_json]
type = "remap"
inputs = ["my_source"]
source = '''
. = parse_json!(string!(.message))
'''
[transforms.remap_keys]
type = "remap"
inputs = ["parse_json"]
source = '''
. = map_keys(., recursive: true) -> |key| { replace(key, r'^_*(?P<field_name>[A-Z0-9]+(?:_[A-Z0-9]+)*)', "$$field_name") }
'''
[sinks.my_sink]
type = "console"
inputs = ["remap_keys"]
encoding.codec = "json" Reference: replace
|
Thanks for responding to this question @iFurySt and opening the PR to update the docs. I'll close this out, but let me know if you have more questions @Jerrimikkihvatai . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A note for the community
Problem
Hello!
I am trying to change keys names from journald sink as some fields has underscore(s) as prefix and elastic/opensearch treats them as system fields.
My common message looks like this
I want to get this
My config looks like this
I found this expression on vector docs
https://vector.dev/docs/reference/vrl/functions/#replace-examples-replace-with-capture-groups
I have tested this expression in vector vrl processor, but when I add it to my config file, vector refuses to start with error message
I also tried to use replace_with function, but vector also says that there is no match.field_name variable
Configuration
Version
Vector image 0.39/0.40-debian
Debug Output
Example Data
No response
Additional Context
No response
References
No response
The text was updated successfully, but these errors were encountered: