Last active
February 8, 2024 16:37
-
-
Save paul-butcher/45f2f33dac3c59b28f704b60e56842b8 to your computer and use it in GitHub Desktop.
An Elasticsearch runtime field to remove some impertinent confounding content from a log entry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(!doc.containsKey("log.keyword") || doc['log.keyword'].empty){ | |
| emit(""); | |
| } else { | |
| def log = doc['log.keyword'].value; | |
| if (log != null) { | |
| int closingBracketIndex = log.lastIndexOf(']'); | |
| if (closingBracketIndex > 0) { | |
| emit(log.substring(closingBracketIndex+1)); | |
| return; | |
| } | |
| emit(log) | |
| } | |
| } | |
| emit(""); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was recently trying to find unique instances of a common error reported in some logs. However, these logs all contained some preamble about the process that raised the error. e.g.
Creating a report on this was a bit of a challenge in Kibana, as all of these rows are unique, but WRT what I was interested in, there are two unique values here, and one of them appears twice.
To deal with this, I created a runtime field. It's slow and a bit of a palaver, but it works.
This Painless script strips off everything up to ']'