MapReduce: grouping and filtering

I have the following task: got all users from site and where timestamp from X to Y and has events “Proposal start”, “Proposal end” also group them by the timestamp.

So I wrote the following map function:

function (doc, meta) {
if (meta.type === ‘json’ && doc.type === ‘session’ && doc.events.length > 0) {
for (var i=0; i < doc.events.length; i++){
emit([doc.site, doc.ts.toString(), doc.events[i]], 1);
}
}
}

…reduce is just a _count.

I test my MapReduce with the next params:
startkey = [“site.com”, “1384293600000”, “Proposal start”]
endkey = [“site.com”, “1385330399999”, “Proposal end”]
group_level=2
reduce=true

But as a result, I get the data that do not meet the specified parameters. I get the data that satisfy the conditions of only the first two arguments site and timestamp.

Please help me, tell me where I’m wrong.

Group_level elements numbers are not set like most programming languages array or lists … of [0,1,2,3 …etc] but rather [1,2,3,4 … etc].

startkey = ["site.com", "1384293600000", "Proposal start"] endkey = ["site.com", "1385330399999", "Proposal end"] group_level=2

Yes, I know about the specific numbering for gepup_level. When you set a group_level=2 the filter works only on the first two elements. This is my problem, I need to filter for all elements, not only for the first two.

Could you post an example of the output of the view that you are currently getting and could you show example of the output you would like to have?

Here’s what I got:

[“site.com”,“1384297200000”,“Proposal end”] 10
[“site.com”,“1384297200000”,“Proposal start”] 64
[“site.com”,“1384297200000”,“Viewed_contacts_in_search_results”] 85

params:
startkey = [“site.com”, “1384297200000”, “Proposal end”]
endkey = [“site.com”, “1384297200000”, “Proposal start”]
group_level = 3
reduce = 3
stale = false

Here’s what I expected:

[“site.com”,“1384297200000”,“Proposal end”] 10
[“site.com”,“1384297200000”,“Proposal start”] 64

I expected that the third value must be only the “Proposal end” or “Proposal start”.