You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by cdr53x <cd...@free.fr> on 2010/11/01 17:56:11 UTC
Complex keys and ranges
Hello,
I've read all the docs/wiki again but cannot find anything related to
views usage when keys are complex JSON objects.
Especially, there are no explanations nor examples of how the ranges (
startkey/endkey ) are supposed to behave with complex keys.
For instance let's presume we have the a view with the following map
function :
function(doc) {
...
emit({ 'date' : created_at , 'author' : author}, null) ;
}
Would it be possible to "filter" on both date and author ?
For instance get all the docs created in a given time range by a given
author , by passing a range like :
start_key : { 'date' : '201002030000.' , author : 'adams' }
end_key : { 'date' : '201003030000.' , author : 'adams' }
?
I have tried this however it does not seem to work that way, so if
anyone has some info on how this should work, I'd really appreciate
Thanks in advance,
cdrx
Re: Complex keys and ranges
Posted by Filipe David Manana <fd...@apache.org>.
Also note that it's "startkey" and "endkey", not "start_key" nor "end_key".
On Mon, Nov 1, 2010 at 5:10 PM, Paul Davis <pa...@gmail.com> wrote:
> On Mon, Nov 1, 2010 at 12:56 PM, cdr53x <cd...@free.fr> wrote:
>> Hello,
>>
>> I've read all the docs/wiki again but cannot find anything related to views
>> usage when keys are complex JSON objects.
>>
>> Especially, there are no explanations nor examples of how the ranges (
>> startkey/endkey ) are supposed to behave with complex keys.
>>
>> For instance let's presume we have the a view with the following map
>> function :
>>
>> function(doc) {
>> ...
>> emit({ 'date' : created_at , 'author' : author}, null) ;
>> }
>>
>>
>> Would it be possible to "filter" on both date and author ?
>>
>> For instance get all the docs created in a given time range by a given
>> author , by passing a range like :
>>
>> start_key : { 'date' : '201002030000.' , author : 'adams' }
>> end_key : { 'date' : '201003030000.' , author : 'adams' }
>>
>> ?
>>
>> I have tried this however it does not seem to work that way, so if anyone
>> has some info on how this should work, I'd really appreciate
>>
>> Thanks in advance,
>>
>> cdrx
>>
>
> View collation is specified here:
> http://wiki.apache.org/couchdb/View_collation#Collation_Specification
>
>
> In short, no, its not possible to filter on multiple members of an
> object key. Generally speaking you shouldn't use object keys as they
> can lead to confusing behavior that is dependent on the various JSON
> libraries used for serialization. If you need complex keys its
> generally best to stick to Arrays as their sorting behavior easier to
> reason about.
>
> HTH,
> Paul Davis
>
--
Filipe David Manana,
fdmanana@gmail.com, fdmanana@apache.org
"Reasonable men adapt themselves to the world.
Unreasonable men adapt the world to themselves.
That's why all progress depends on unreasonable men."
RE: Complex keys and ranges
Posted by Nils Breunese <N....@vpro.nl>.
You can do AND queries using standard views. You can't do OR queries that way. Check out couchdb-lucene: http://github.com/rnewson/couchdb-lucene
Nils.
________________________________________
Van: cdr53x [cdr53x@free.fr]
Verzonden: maandag 1 november 2010 19:09
Aan: user@couchdb.apache.org
Onderwerp: Re: Complex keys and ranges
On 11/01/2010 06:10 PM, Paul Davis wrote:
> In short, no, its not possible to filter on multiple members of an
> object key.
Ok, that is sad, but clear enough ;)
> Also note that it's "startkey" and "endkey", not "start_key" nor "end_key".
>
>
Yes of course, just a typo in my message
Thanks for your answers.
Actually I thought that maybe complex key could be used in order to
perform a query with multiple criterias.
But it seems that the only way of having such an "intersection" would
be to use the "multiview" feature, when and if ever it is functional ...
BTW are there any news on the progress of this module and possible
integration in the couch trunk ?
Regards,
cdrx
------------------------------------------------------------------------
VPRO
phone: +31(0)356712911
e-mail: info@vpro.nl
web: www.vpro.nl
------------------------------------------------------------------------
Re: Complex keys and ranges
Posted by cdr53x <cd...@free.fr>.
On 11/01/2010 06:10 PM, Paul Davis wrote:
> In short, no, its not possible to filter on multiple members of an
> object key.
Ok, that is sad, but clear enough ;)
> Also note that it's "startkey" and "endkey", not "start_key" nor "end_key".
>
>
Yes of course, just a typo in my message
Thanks for your answers.
Actually I thought that maybe complex key could be used in order to
perform a query with multiple criterias.
But it seems that the only way of having such an "intersection" would
be to use the "multiview" feature, when and if ever it is functional ...
BTW are there any news on the progress of this module and possible
integration in the couch trunk ?
Regards,
cdrx
Re: Complex keys and ranges
Posted by Paul Davis <pa...@gmail.com>.
On Mon, Nov 1, 2010 at 12:56 PM, cdr53x <cd...@free.fr> wrote:
> Hello,
>
> I've read all the docs/wiki again but cannot find anything related to views
> usage when keys are complex JSON objects.
>
> Especially, there are no explanations nor examples of how the ranges (
> startkey/endkey ) are supposed to behave with complex keys.
>
> For instance let's presume we have the a view with the following map
> function :
>
> function(doc) {
> ...
> emit({ 'date' : created_at , 'author' : author}, null) ;
> }
>
>
> Would it be possible to "filter" on both date and author ?
>
> For instance get all the docs created in a given time range by a given
> author , by passing a range like :
>
> start_key : { 'date' : '201002030000.' , author : 'adams' }
> end_key : { 'date' : '201003030000.' , author : 'adams' }
>
> ?
>
> I have tried this however it does not seem to work that way, so if anyone
> has some info on how this should work, I'd really appreciate
>
> Thanks in advance,
>
> cdrx
>
View collation is specified here:
http://wiki.apache.org/couchdb/View_collation#Collation_Specification
In short, no, its not possible to filter on multiple members of an
object key. Generally speaking you shouldn't use object keys as they
can lead to confusing behavior that is dependent on the various JSON
libraries used for serialization. If you need complex keys its
generally best to stick to Arrays as their sorting behavior easier to
reason about.
HTH,
Paul Davis
Re: Complex keys and ranges
Posted by AJ ONeal <co...@gmail.com>.
In connection with Node.js there's a couchdb plugin for sphinx (C++) /
limestone / search.
https://github.com/kurokikaze/limestone
https://github.com/kurokikaze/node-search-engine
I haven't tried it, but I hope to investigate it more later. I don't want
lucene for the same reason - JVM yuck.
AJ ONeal
On Tue, Nov 2, 2010 at 5:20 AM, cdr53x <cd...@free.fr> wrote:
> On 11/02/2010 10:26 AM, Nils Breunese wrote:
>
>>
>> You can run couchdb-lucene on a separate server if you want. Anyway, we
>> are very happy with couchdb-lucene and I think it's a much more mature
>> solution than multiview, which is still in development. Also, Lucene can do
>> a lot more than multiview I believe (but maybe you don't need that extra
>> funcionality).
>>
>>
> Actually I was more looking at a way of optimizing a single server ;)
>
> But I will give lucene a try in all cases.
>
> Regards,
>
> cdrx
>
>
>
Re: Complex keys and ranges
Posted by cdr53x <cd...@free.fr>.
On 11/02/2010 10:26 AM, Nils Breunese wrote:
>
> You can run couchdb-lucene on a separate server if you want. Anyway, we are very happy with couchdb-lucene and I think it's a much more mature solution than multiview, which is still in development. Also, Lucene can do a lot more than multiview I believe (but maybe you don't need that extra funcionality).
>
Actually I was more looking at a way of optimizing a single server ;)
But I will give lucene a try in all cases.
Regards,
cdrx
Re: Complex keys and ranges
Posted by Nils Breunese <N....@vpro.nl>.
cdr53x wrote:
> Basicaly I tend to avoid a JVM whever it's possible, but seems that with
> lucene it is not the case. I presume it will add an extra load to the
> server, and that we'll run into the usual Java scaling issues wich is
> something we initially wanted to avoid ...
You can run couchdb-lucene on a separate server if you want. Anyway, we are very happy with couchdb-lucene and I think it's a much more mature solution than multiview, which is still in development. Also, Lucene can do a lot more than multiview I believe (but maybe you don't need that extra funcionality).
> It's a pity that couchdb mutiview does not seem to progress, it would be
> a realy nice feature for guys developing "usual management" software
> that basically requires an OR or set query criteria.
I haven't followed its development very closely, but I believe it's still being worked on. If it's important to you, maybe you could lend a hand?
Nils.
------------------------------------------------------------------------
VPRO
phone: +31(0)356712911
e-mail: info@vpro.nl
web: www.vpro.nl
------------------------------------------------------------------------
Re: Complex keys and ranges
Posted by cdr53x <cd...@free.fr>.
> You need to change your map function to emit [author, date] to be able
> to search for for author and time-range.
>
> emit([author, created_at], null);
>
> Now query for startkey=["adams", "201002030000"]&endkey=["adams",
> "201003030000"].
>
This is ok, however, as I want to have all the changes for a given time
range and a _set_ of authors, the key range on the design doc will not
do it.
I'll check out lucene for couchdb as a possible alternative, event
though I'd realy prefer to have such a feature in couchdb and not in a
separate module that also requires a JVM...
Basicaly I tend to avoid a JVM whever it's possible, but seems that with
lucene it is not the case. I presume it will add an extra load to the
server, and that we'll run into the usual Java scaling issues wich is
something we initially wanted to avoid ...
It's a pity that couchdb mutiview does not seem to progress, it would be
a realy nice feature for guys developing "usual management" software
that basically requires an OR or set query criteria.
Thanks again,
Regards,
cdrx
Re: Complex keys and ranges
Posted by Anand Chitipothu <an...@gmail.com>.
2010/11/1 cdr53x <cd...@free.fr>:
> Hello,
>
> I've read all the docs/wiki again but cannot find anything related to views
> usage when keys are complex JSON objects.
>
> Especially, there are no explanations nor examples of how the ranges (
> startkey/endkey ) are supposed to behave with complex keys.
>
> For instance let's presume we have the a view with the following map
> function :
>
> function(doc) {
> ...
> emit({ 'date' : created_at , 'author' : author}, null) ;
> }
>
>
> Would it be possible to "filter" on both date and author ?
>
> For instance get all the docs created in a given time range by a given
> author , by passing a range like :
>
> start_key : { 'date' : '201002030000.' , author : 'adams' }
> end_key : { 'date' : '201003030000.' , author : 'adams' }
>
> ?
>
> I have tried this however it does not seem to work that way, so if anyone
> has some info on how this should work, I'd really appreciate
You need to change your map function to emit [author, date] to be able
to search for for author and time-range.
emit([author, created_at], null);
Now query for startkey=["adams", "201002030000"]&endkey=["adams",
"201003030000"].
Remember that couchdb view a just a btree, all it does it keeping the
view sorted by key. You need to write your map function such that the
data you want to query comes together in the sorted order, so that you
can query the view by range.
Anand