I have a Spring Boot app, and an Elastic stack (Elasticsearch + Kibana + Filebeat, no Logstash). I want to log some information whenever a request comes to my Spring app (say, the request url and request user id).
A first naive way is to simply log that (log.info("request comes url={} user={}", url, user);
). Then filebeat will happily collect that into my elasticsearch and I can visualize it using Kibana.
However, I do not want these data to be mixed with all the other logs in the filebeat-*
index pattern. I want them to be, say, request-info
(or request-info-*
) while the other normal log data in filebeat-*
index pattern. Is there any way to do so? Thank you very much!
You can use a conditional output in your filebeat.yml
based on a string present in your message.
Something like:
output.elasticsearch:
hosts: ["http://localhost:9200"]
indices:
- index: "request-info-%{+yyyy.MM.dd}"
when.contains:
message: "request comes"
If your message contains the string request comes
it will be sent to the index request-info-2020.11.28
for example, if it does not contains, it will be sent to the default index.
You can read more about the options to the elasticsearch output
in this documentation link
Oh great, thank you! I knew
index
andwhen
, but did not think that it can be conditionally set like this :)