I have a need to query the logs in Elasticsearch through Kibana in a certain way that I will explain soon. I'll try my best to explain what I'm looking for and hopefully someone can tell me if it is possible via Kibana or whether I should just query elastic directly.
I log incoming requests to my system and whatever follows up to the point where it has to return a response. All those logs are grouped by a correlation ID. So with a specific correlation ID I can see the incoming request, any potential logged errors, any further propagated logs and then the response message.
So let's say I have a DEBUG log (with a correlation ID) that contains the message "Condition met". This log is not logged everywhere and every time, only when a certain condition was met during a request (this is purely hypothetical). Now I would like to look for the logs that contains this phrase "Condition met". This is easy as I can see all the entries who's message is "Condition met". But now I want to include all the logs for that entry that has the same Correlation ID.
So then I will also see the request and response messages alongside the message "Condition met" that are related.
Is there a way to query or visualize this in Kibana or is it only possible to query this via elastic search? If the latter, how could I ask elastic search to give me those results?
What I've tried so long:
I've setup an elastic search query:
POST my_index/_search
{
"aggs": {
"my_aggr": {
"aggs": {
"messagefield": {
"max": {
"script": "doc['Message.keyword'].size() > 0 && doc['Message.keyword'].value.contains('Condition met')"
}
},
"hasMessage": {
"bucket_selector": {
"buckets_path": {
"var1": "messagefield"
},
"script": "params.var1 == 1"
}
}
},
"terms": {
"field": "CorrelationId.keyword",
"size": 10
}
}
},
"size": 0
}
And it returns:
{
"took" : 661,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 10000,
"relation" : "gte"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"my_aggr" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 263158,
"buckets" : [
{
"key" : "CID001F934C53564805B207F0068A0E0803",
"doc_count" : 11,
"messagefield" : {
"value" : 1.0
}
},
{
"key" : "CID0091D8BED2664C5F8A5730E249C626C0",
"doc_count" : 11,
"messagefield" : {
"value" : 1.0
}
},
{
"key" : "CID0231AA20382A4E69A5041C8E10FD6EF1",
"doc_count" : 11,
"messagefield" : {
"value" : 1.0
}
},
{
"key" : "CID057831D9F1504F21AAAF10955A35D55A",
"doc_count" : 11,
"messagefield" : {
"value" : 1.0
}
},
{
"key" : "CID05F8E51D7EF64277BF0157787047C731",
"doc_count" : 11,
"messagefield" : {
"value" : 1.0
}
},
{
"key" : "CID073B8FC7295B43BAB0CCC7021CC1AE73",
"doc_count" : 11,
"messagefield" : {
"value" : 1.0
}
}
]
}
}
}
This is almost what I'm looking for, the only thing now is to actually expand each bucket to include the docs that are aggregated in that bucket. Not sure if that is possible. I don't think I'll be able to setup a query like this using Kibana itself.