CouchDB _approx_count_distinct

15 Views Asked by At

I'm having a problem using _approx_count_distinct reduce function. Based on the documentation _approx_count_distinct is loosely based on Hyperloglog algorithm.

I can't get this to work.

May map function:

function (doc) {
  if (doc.folder && doc.from && doc.created) {
    var splitted = doc.from.split("#");
    var address = splitted[splitted.length-1];
    emit([doc.folder, address,doc.created], 1);
  }
}

Here is my query I'm trying to do:

curl http://localhost:5984/mydb?startkey=['sent', 'abc', 0]&endkey=['sent', 'abc, 1709676004000]&group_level=3

I always get all of the rows (not filtered by 'sent' folder). I'm doing something fundamentally wrong here due to lack of understanding of the inner workings of _approx_count_distinct reducer.

Is there a way to think about this correctly?

I'm trying to get out a count .. simple as that.

1

There are 1 best solutions below

0
y0gie007 On

The problem I had was incorrect (although executable) formatting of the URL.

The solution was to add my query into Postman and see the corresponding URL encoding for the formatted curl command.