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 D9527435B for ; Fri, 27 May 2011 09:17:04 +0000 (UTC) Received: (qmail 67984 invoked by uid 500); 27 May 2011 09:17:03 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 67928 invoked by uid 500); 27 May 2011 09:17:03 -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 67920 invoked by uid 99); 27 May 2011 09:17:03 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 May 2011 09:17:03 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of torsteinkrausework@gmail.com designates 209.85.160.52 as permitted sender) Received: from [209.85.160.52] (HELO mail-pw0-f52.google.com) (209.85.160.52) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 May 2011 09:16:55 +0000 Received: by pwi4 with SMTP id 4so989930pwi.11 for ; Fri, 27 May 2011 02:16:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=zIBkeqTpFjhExdV2iJLuCoJjmLDOxhpxcHuJrl/G4po=; b=T5L+30lgN4aK+3hsYjThQ/IS0tBnwLrY8+PwRg4t7YSENDEsbuUdIZiVq1wxp5K0AO bXia5OPJ9H7lf7XQzWYrejjUIOhRd8uEZlf40c64Fo0Vg+yZH74zHauMFe0OmrWN1ltQ 1viOwexzcX9WF50u/NpD3wg1pMtIKmy2E27Zo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=SKqAxwUlLPAuivPtIKgv4IITHTO+MD/vemkeRHVkd5tM8jq+JDu1By5+j1B62rk3BT PnWVo1MRisg4mETmepOMxhYqa1UkI4zx99pdyF/drn+75b/huYdPAMYARmqx47TdBkpS /N+uF1jc9RSmd6QTuuxoW1fAZi7VYx3CDqsXg= Received: by 10.142.150.32 with SMTP id x32mr280100wfd.287.1306487794772; Fri, 27 May 2011 02:16:34 -0700 (PDT) Received: from [192.168.1.105] (114-44-176-76.dynamic.hinet.net [114.44.176.76]) by mx.google.com with ESMTPS id y16sm1300920wfg.23.2011.05.27.02.16.32 (version=SSLv3 cipher=OTHER); Fri, 27 May 2011 02:16:33 -0700 (PDT) Message-ID: <4DDF6BEE.8070907@gmail.com> Date: Fri, 27 May 2011 17:16:30 +0800 From: Torstein Krause Johansen User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110402 Icedove/3.1.9 MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: Complex queries & results References: <4DDDFD4E.9060701@gmail.com> <4DDF164A.7030009@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi there, On 27/05/11 16:01, Gabor Ratky wrote: > The order of your components of your keys matter. There is no way to ignore the first element of your key. You should instead reorder your keys based on what you're trying to count / query. > > emit([created_at, a_name, one_id, another_id]); > > and querying with: > > ?group=true&group_level=2&startkey=["2011-05-26"]&endkey=["2011-05-27", {}] > > results in: > > { > "key": ["2011-05-26", "Lisa"], > "value": 1 > }, > { > "key": ["2011-05-26", "John"], > "value": 2 > }, > { > "key": ["2011-05-27", "John"], > "value": 1 > } > > You can of course emit not just days, but also weeks, months, quarters if that's what you always want. If it arbitrary and you need to aggregate the names afterwards from this smaller set, yo should do it in the client (whoever calls CouchDB to get this information out). Mhmm, ok, thanks for explaining this. It means though, that for every unique time stamp that a_name has an entry, there will be a corresponding count returned (like the three you listed above). Hence, if a_name has 1000 entries at slightly different times within the time range I'm searching for (my created_at includes seconds), I will get 1000 such entries back. > tldr; The elements and order of the keys determines the order of the index and you can only filter for a contiguous part of that index with startkey / endkey. Ok, thanks a lot for your confirmation! Cheers, -Torstein