Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B719D17FF2 for ; Fri, 10 Oct 2014 14:38:08 +0000 (UTC) Received: (qmail 79738 invoked by uid 500); 10 Oct 2014 14:38:07 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 79679 invoked by uid 500); 10 Oct 2014 14:38:07 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 79667 invoked by uid 99); 10 Oct 2014 14:38:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Oct 2014 14:38:07 +0000 X-ASF-Spam-Status: No, hits=1.8 required=5.0 tests=HTML_FONT_FACE_BAD,HTML_MESSAGE,RCVD_IN_DNSWL_LOW X-Spam-Check-By: apache.org Received-SPF: unknown (athena.apache.org: error in processing during lookup of gijs@prezly.com) Received: from [209.85.212.169] (HELO mail-wi0-f169.google.com) (209.85.212.169) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Oct 2014 14:38:02 +0000 Received: by mail-wi0-f169.google.com with SMTP id cc10so4488428wib.4 for ; Fri, 10 Oct 2014 07:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prezly.com; s=google; h=mime-version:from:date:message-id:subject:to:content-type; bh=NdAr2s+5pMnZL2YRfLEQswPBWc1om6NHFtRDTM1pSHo=; b=Db0XQZgwDZqrgbI6svqjB2nnUmL8JOZKIUCw7PIN22+m5MGa7OFbsY4wC0YlScgj0w Tqj2Qys7v6M3Sm0Yzng945d3nStjqp+QY1zmqT+RyDx3a1eWUbewAfk2cjsVVtQ3HNYL PaTJLJY3THuXKIKbosCLIe8pXxE9KL2ud6x20= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-type; bh=NdAr2s+5pMnZL2YRfLEQswPBWc1om6NHFtRDTM1pSHo=; b=KRPZ3WT/rJPkSy5htLeuOn7alI3R4q2D61ZulZkZfwsTvOXCW7GTuF/pNAq96HYGSj dSMAJPwlZeqGcM7XMzXHEv2SJK+Xd0pywmo4YJkzNscps7boia9E0LU5xlvZd+DsEeMS 73B3KIUkkXw1DJ6tSAHGYBUjkDsA1vTZgmT5wNM4fhztiFTCQOGhr0PAZ1KVn6iTeWHy AE23MdKFCqzBdbqKvyO3TAjDozfh0AIjKocAaTGctVML1BKc/xZ3tStyaIwMEY0PPkKD cHqLo4ieziRwYvJrQDILJVTE/RAkGt1KmtujgJX6esuoAxxt7EbZXzS0qC4yl6VEo9aT 54Jw== X-Gm-Message-State: ALoCoQmENu6Td6AdzQ/aRIK1TVJzYA9p8LsCDUooc0AIB9guU6Y2Xre+66jk0Z1uGd1oCyC9Bwrs X-Received: by 10.194.202.138 with SMTP id ki10mr5170781wjc.68.1412951861455; Fri, 10 Oct 2014 07:37:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.220.106 with HTTP; Fri, 10 Oct 2014 07:37:21 -0700 (PDT) X-Originating-IP: [81.82.199.46] From: Gijs Nelissen Date: Fri, 10 Oct 2014 16:37:21 +0200 Message-ID: Subject: Email statistiscs : using reduce for uniques To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=047d7b873aeec971640505127dd1 X-Virus-Checked: Checked by ClamAV on apache.org --047d7b873aeec971640505127dd1 Content-Type: text/plain; charset=UTF-8 Hi, I have a couchDB view with about 20 million very simple events: key: [1,1,1,1,'deliver'] { email: "john@example.net", ip: "..."} key: [1,1,1,1,'open'] { email: "john@example.net", ip: "..."} key: [1,1,1,1,'click'] { email: "john@example.net", ip: "..."} key: [1,1,1,2,'deliver'] { email: "john@example.net", ip: "..."} key: [1,1,1,2,'open'] { email: "john@example.net", ip: "..."} key: [1,1,1,2,'open'] { email: "john@example.net", ip: "..."} <- second open by user key: [1,1,1,2,'open'] { email: "john@example.net", ip: "..."} <- third open by user Now i want to do very mailchimp/campaignmonitor like summary per campaign (key[3}) that show nr of unique delivers, nr of unique opens, nr of unique clicks. I have been trying different approaches to achieve this by using a custom map and reduce function. //map function(doc) { emit([doc.license.id,10, doc.release.id, doc.email.id, doc.contact.id, doc.type], null); } //reduce function(keys, values, rereduce){ if (rereduce){ var result_rereduce = { contacts: values[0].contacts, open: values[0].open, click: values[0].click, bounce: values[0].bounce, unsubscribe: values[0].unsubscribe, unopened: values[0].unopened }; for(var i=1,e=values.length; i