Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Log Analytics switch statement / pattern matching

I'm trying to process my Application Insights data using Application Insights Analytics and Log Analytics Query Language. What I'd like to have is something like switch statement in C# or pattern matchng in F#. So the pseudocode would be like this:

requests
| where timestamp > now(-1d)
| project endpoint = (switch(name){ {case: "POST /api/jobs/search", then: "Jobs Search"}, {case: "POST /api/offices/search", then: "Office Search"} ...})

Or maybe there is some kind of workaround to define a dictionary-like structure and then use that structure in my query

Any ideas ?

like image 326
mickl Avatar asked Oct 21 '25 03:10

mickl


1 Answers

What you're looking for is the case() function.

requests
| where timestamp > ago(1d)
| project endpoint = case(
    name == "POST /api/jobs/search", "Jobs Search",
    name == "POST /api/offices/search", "Office Search",
    "Unknown")
like image 130
joaqo Avatar answered Oct 23 '25 21:10

joaqo