Do 'reduce' with results from Cloudant search?

241 views Asked by At

In Cloudant is it possible to do something like a reduce on a set of results from a search index (as opposed to a view)?

In my case, I'd like to find all documents that have a title value that includes 'foo', then for each of these sum the total number of views, based on each document's viewCount value.

1

There are 1 answers

5
bradnoble On BEST ANSWER

You can't reduce but you can use faceting to get counts.

Example query ?q=*:*&counts=["type"]

Example response

{
  "total_rows":100000,
  "bookmark":"g...",
  "rows":[...],
  "counts":{
    "type":{
      "sofa": 10, 
      "chair": 100,
      "lamp": 97
    }
  }
}

https://docs.cloudant.com/search.html#faceting