Hey,
I have a bucket in which all docs structures are identical and have the following format:
“dateTime”: 1445666400000,
“favorites”: 0,
“clicks”: 0,
…
…
“customerId”: 15,
“campaignId”: 5819651,
“campaignName”: “twitter_CO_AU_android_HL”,
most of my needs from this documents is to summarize on each of the fields (favorites, clicks, etc…)
now to my understanding summarizing is faster using the map-reduce than it is using N1QL (from my experience the difference is huge.)
the only problem is i want to query dynamically according to parts of the campaignName in range of customerId and dateTime.
for example one of my reduce function currently look like this:
function (doc, meta) {
var idx = (meta.id).indexOf(":");
var docType = (meta.id).substring(0,idx);
if(meta.type == ‘json’ && docType == ‘twitterCampaignsStatistics’ && doc.customerId && doc.campaignId && doc.dateTime){
if(doc.campaignName.indexOf(“CO_”) > -1){
emit([doc.customerId,doc.dateTime],doc.clicks);
}
}
}
Which brings me to two questions:
- is there a way i switch the : " if(doc.campaignName.indexOf(“CO_”) > -1)" in way i can sometimes query for “Android” and otheres for “Iphone” and so on… or do i need to build a view for every regex i need? (because i want the possibility to pass the regex dynamically in some way…)
- can i sum into different results the values of “favorites”, “clicks”, etc… in the same view?
Thanks.