I'm working on an app that uses RavenDB on the back end. It's my first time using Raven, and I'm struggling with Map/Reduce.
I have been reading the doc's, but unfortunately I'm not getting anywhere in the process.
Basically I have thousands of documents like this.
{
.....
"Severity": {
"Code": 6,
"Data": "Info"
},
"Facility": {
"Code": 16,
"Data": "Local Use 0 (local0)"
},
.....
}
And out of it, I need to make a single query with output that looks like this.
{"Severity": [
{"Emergency":0},
{"Alert":0},
{"Critical":0},
{"Error":0},
{"Warning":0},
{"Notice":0},
{"Info":2711},
{"Debug":410}
],
"Facility": [
{"Kernel Messages":0},
{"User-Level Messages":0},
{"Mail System":0},
{"System Daemons":0},
{"Security/Authorization Messages":0},
{"Internal Syslogd Messages":0},
{"Line Printer Subsystem":2711},
{"Network News Subsystem":410},
....
{"Local Use 0 (local0)": 2574},
...
]}
Whereby the "Key" in the Severity/Facility Array is the Data
portion of the above json data, and the "value" in the Severity/Facility Array is the document Count
for each Code
type.
Example:
Using the above data as a guideline,
There are 2711 documents in my database with an
Info
severity.
There are 410 documents in my database with aDebug
severity.
There are 2574 documents in my database with alocal0
facility.
etc...
What I'd like to do is generate the appropriate indexes when the app starts up (or check if they already exist), but I don't even know where to begin.
note: the app needs to generate the index, it's not enough to just manually write it into the RavenDB Web UI.