Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 82982 invoked from network); 14 Mar 2011 16:18:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Mar 2011 16:18:25 -0000 Received: (qmail 18449 invoked by uid 500); 14 Mar 2011 16:18:23 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 18403 invoked by uid 500); 14 Mar 2011 16:18:23 -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 18392 invoked by uid 99); 14 Mar 2011 16:18:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Mar 2011 16:18:23 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of kinleyd@gmail.com designates 209.85.212.52 as permitted sender) Received: from [209.85.212.52] (HELO mail-vw0-f52.google.com) (209.85.212.52) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Mar 2011 16:18:17 +0000 Received: by vws16 with SMTP id 16so3160624vws.11 for ; Mon, 14 Mar 2011 09:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=lVf4XzCBZ4BflQYVVShceE9+vggKzOAN6xHkwi6Ee5Q=; b=EZiAdyuGHYpIUltfGMRuvB08znQWQzZEoVjLBXSZZzzVHfoOjYW1VTPoIGn6++oB87 4Uk8RGX24G5DAhqD38fa6gmIEAMdt2QtbyPfk+Wl7FO5bCbM/oaruPttEDEp7IrDd1J2 7JAFCmTqDfatC+3BzWKemgjvua7km8wX2wCoQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=av/nqA+Jr+UPjNH9NkY93ylSEX00ygo1waKKRdKxgcERUZzBvC2AZdSuh4sR9IaX2V SnF4JWB6Aba+gkAa6/Z35LATBqkgdIv1XVtRW86ZEF0THv3177BMAm0TdguEiBzbJ6+P iPCd5Kmvm9j2ERCLUj0jU2Gc6tY2e72krNfYo= MIME-Version: 1.0 Received: by 10.220.6.81 with SMTP id 17mr2792014vcy.207.1300119475804; Mon, 14 Mar 2011 09:17:55 -0700 (PDT) Received: by 10.220.165.143 with HTTP; Mon, 14 Mar 2011 09:17:55 -0700 (PDT) In-Reply-To: References: Date: Mon, 14 Mar 2011 22:17:55 +0600 Message-ID: Subject: Re: filtering on timestamp + aggregation on another field From: Kinley Dorji To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi Aroj, Unlike in SQL, CouchDB views cannot be filtered by value. They can be only filtered by key for performance reasons as the key is where the indexing action takes place. So the solution for you would be to have a view of this type: emit (doc.timestamp, {country:doc.country, city:doc.city, hospital:doc.hospital, rooms:doc.rooms}); // this representing the output of the map stage This would create a view that you could filter based on your start and end time stamp keys for the desired period. The aggregation would take place in your code in the reduce stage, which would manipulate the json that you created on the value side of your key/value pair for a particular time stamp to get whatever aggregation you need. Hope that helps. On Mon, Mar 14, 2011 at 10:02 PM, Aroj George wrote: > Thanks Kinley. But just emitting the timestamp does not solve the problem > for us. > > We want to be able to emit something like, > > [India,Mahrashtra,Pune,timestamp] =A0(where Pune is a city in state > Maharashtra which is in country India) > > and then we would like to filter using the timestamp and group by locatio= n > on say India as, > > *startkey=3DIndia,%,%,timestamp1 & endkey=3DIndia,%,%,timestamp2 & group_= level =3D > 1* > > This should give me all results grouped by location India, but filtered o= ut > between the two timestamps. > > But ofcourse there is no % filter possible it seems. > > A SQL equivalent would be, > > select * from table where timestamp > timestamp1 and timestamp < timestam= p2 > group by country. > > What's the right thing to do when faced with such a requirement? > > we could do a temp view like below? > > if (doc.timestamp > T1 & doc.timestamp < T2) emit(doc.location_path,doc) > > But aren't temp views considered bad for performance. > > Please do suggest the best way to solve this problem in couchdb. > > > Rgds, > Aroj > > > On 14 Mar 2011 18:59, "Kinley Dorji" wrote: >