incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Samuel Newson <rnew...@apache.org>
Subject Re: Question on views
Date Mon, 09 Jun 2014 21:34:22 GMT
There are no wildcards. :)

Views are fully ordered by the key value according to the defined collation order documented
here: https://wiki.apache.org/couchdb/View_collation

Your example  startkey=["target ID"]&endkey=["target ID",{}] 

This works for any number or string in the second position, as any object is 'higher' than
any number or string. If you emitted objects as the second item, then the query would not
return any non-empty object in that position.

Views support exact key lookup and contiguous key range lookup only. A POST variant lets you
perform multiple exact key lookups in a single request as a refinement.

B.


On 9 Jun 2014, at 19:16, Guilherme Andrade <g@gandrade.net> wrote:

> I'm sorry, it looks like I've induced you in error; too much Erlang ;). In any case,
range queries make use of 'startkey' and 'endkey' instead of just 'key'.
> 
> I don't remember the exact syntax for complete wildcards but Stack Overflow gave me the
answer. Looks like this might do:
> 
>     startkey=["target ID"]&endkey=["target ID",{}] 
> 
> 
> Cheers,
> 
> 
> [1]: https://stackoverflow.com/questions/11623154/couchdb-querying-array-key-value-for-first-key-element-only
> 
> On 09-06-2014 19:05, Ramanadham, Radhika wrote:
>> Thanks.
>> I think I can change the keys -> key2, key1. 
>> What would be the query?
>> 
>> The below throws me an error.
>> 
>> 
>> http://127.0.0.1:5984/longevity/_design/perfstats/_view/by_server?key=
>> [key2,_]
>> 
>> example:
>> 
>> 
>> http://127.0.0.1:5984/longevity/_design/perfstats/_view/by_server?key=
>> [" lglod025.lss.emc.com",_]
>> 
>> What am I doing wrong?
>> 
>> -----Original Message-----
>> From: Guilherme Andrade [
>> mailto:g@gandrade.net
>> ] 
>> Sent: Monday, June 09, 2014 12:57 PM
>> To: 
>> user@couchdb.apache.org
>> 
>> Subject: Re: Question on views
>> 
>> Unfortunately there's no performant way to do it like that, views have strict ordering
and ranges/subranges are only possible within the confinements of the composite key order.
>> 
>> One way to do it is to have a second view that emits keys in reverse ([key2, key1]);
then you may do a range query based on [key2, _].
>> 
>> Cheers,
>> 
>> On 09-06-2014 17:36, Ramanadham, Radhika wrote:
>> 
>>> Hi,
>>> 
>>> I have a view which has 2 keys- key1 and key2:
>>> 
>>> "by_server": {
>>>                 "map": "function(doc) { if ((doc.type == 'performance_stats'))
 emit([key1, key2],{ 'Start_time':doc.start_time ,'CPU': doc.CPU, 'Memory': doc.Memory, 'FileSystem':doc.FileSystem
}) }"
>>>  },
>>> 
>>> 
>>> If I want to query the view where I need all the rows for key2 and key1 being
anything, how do I do it?
>>> 
>>> Let's say my data is->
>>> 
>>> {"id":"server_lglod025.lss.emc.com_2014-06-09_10:24:18","key":["lglod0
>>> 25.lss.emc.com","SRMSuite_3.0.2_test1"],"value":{"Start_time":"2014-06
>>> -09 09:00:00","CPU":12,"Memory":98,"FileSystem":96}},
>>> {"id":"server_lglod093.lss.emc.com_2014-06-09_11:24:18","key":["lglod0
>>> 93.lss.emc.com","SRMSuite_3.0.2_test2"],"value":{"Start_time":"2014-06
>>> -09 10:00:00","CPU":12,"Memory":98,"FileSystem":97}},
>>> {"id":"server_lglod174.lss.emc.com_2014-06-04_14:01:44","key":["lglod1
>>> 74.lss.emc.com","SRMSuite_3.0.2_test2"],"value":{"Start_time":"2014-06
>>> -04 10:00:00","CPU":67,"Memory":97,"FileSystem":17}},
>>> 
>>> I only want the below 2 rows who have a key2 = SRMSuite_3.0.2_test2, how do I
do it?
>>> 
>>> {"id":"server_lglod093.lss.emc.com_2014-06-09_11:24:18","key":["lglod0
>>> 93.lss.emc.com","SRMSuite_3.0.2_test2"],"value":{"Start_time":"2014-06
>>> -09 10:00:00","CPU":12,"Memory":98,"FileSystem":97}},
>>> {"id":"server_lglod174.lss.emc.com_2014-06-04_14:01:44","key":["lglod1
>>> 74.lss.emc.com","SRMSuite_3.0.2_test2"],"value":{"Start_time":"2014-06
>>> -04 10:00:00","CPU":67,"Memory":97,"FileSystem":17}},
>>> 
>>> Thanks,
>>> Radhika
>>> 
>>> 
>> --
>> Guilherme Andrade
>> 
>> PGP fingerprint: 1968 5252 3901 B40F ED8A  D67A 9330 79B1 35CB 8191
>> 
>> 
>> 
> 
> -- 
> Guilherme Andrade
> 
> PGP fingerprint: 1968 5252 3901 B40F ED8A  D67A 9330 79B1 35CB 8191
> 


Mime
View raw message