Built-in _count Function

    +
    The _count function provides a simple count of the input rows from the map() function, using the keys and group level.

    The keys and group level provides a count of correlated items where the values generated during the map() stage are ignored.

    For example, using the input:

    {
       "rows" : [
          {"value" : 13000, "id" : "James", "key" : ["James", "Paris"] },
          {"value" : 20000, "id" : "James", "key" : ["James", "Tokyo"] },
          {"value" : 5000,  "id" : "James", "key" : ["James", "Paris"] },
          {"value" : 7000,  "id" : "Adam",  "key" : ["Adam",  "London"] },
          {"value" : 19000, "id" : "Adam",  "key" : ["Adam",  "Paris"] },
          {"value" : 17000, "id" : "Adam",  "key" : ["Adam",  "Tokyo"] },
          {"value" : 22000, "id" : "John",  "key" : ["John",  "Paris"] },
          {"value" : 3000,  "id" : "John",  "key" : ["John",  "London"] },
          {"value" : 7000,  "id" : "John",  "key" : ["John",  "London"] }
        ]
    }

    Enabling the reduce() function and using a group level of 1 would produce:

    {
       "rows" : [
          {"value" : 3, "key" : ["Adam" ] },
          {"value" : 3, "key" : ["James"] },
          {"value" : 3, "key" : ["John" ] }
       ]
    }

    The reduction has produce a new result set with the key as an array based on the first element of the array from the map output. The value is the count of the number of records collated by the first element.

    For example, using a group level of 2 generates the following where the counts are for the keys matching both the first two elements of the map output.:

    {
       "rows" : [
          {"value" : 1, "key" : ["Adam", "London"] },
          {"value" : 1, "key" : ["Adam", "Paris" ] },
          {"value" : 1, "key" : ["Adam", "Tokyo" ] },
          {"value" : 2, "key" : ["James","Paris" ] },
          {"value" : 1, "key" : ["James","Tokyo" ] },
          {"value" : 2, "key" : ["John", "London"] },
          {"value" : 1, "key" : ["John", "Paris" ] }
       ]
    }