incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthieu Rakotojaona <matthieu.rakotoja...@gmail.com>
Subject Re: Which view is better optimized ?
Date Tue, 22 Jul 2014 18:48:42 GMT
Hello,

Excerpts from Landry Soules's message of 2014-07-22 11:51:26 +0200:
> emit([doc.age, doc.gender, doc.lastSeen], doc);
> emit([doc.gender, doc.age, doc.lastSeen], doc);

Unless you know what you're doing, you shouldn't emit the full doc as a
value. Views are optimized that values are copied, so it means that
_all_ your docs will be copied, once per view. The trick is that at
query time, there is a special parameter you can pass to the GET [0]:

    Query Parameters:
      [...]
      include_docs (boolean) – Include the associated document with each row. Default is
false.
      [...]

so what you should emit is something like

    emit([doc.age, doc.gender, doc.lastSeen], null);
    emit([doc.gender, doc.age, doc.lastSeen], null);

and use "&include_docs=true" when you query the view, so that you
effectively get what you initially wanted to emit without wasting space.

Regarding your question, you fall in the field of multi-dimensional
queries, which Couchdb isn't suited for. The solution generally is to
use couchdb-lucene or even elasticsearch for something like that.

[0]
http://couchdb.readthedocs.org/en/latest/api/ddoc/views.html#get--db-_design-ddoc-_view-view

-- 
Matthieu Rakotojaona

Mime
View raw message