I'm a bit confused by your example query and your sample document because there are some inconsistencies, but I am going to try to answer your question based on a couple assumptions.
If you are filtering by a single PERIOD value no GROUPBY clause should be required in your SQL statement:
SELECT COUNT(DISTINCT(correlationassetid))
FROM view_asset
WHERE PERIOD = '201705'
Defining the following design document
{
"_id": "_design/howdoi",
"views": {
"filter-by": {
"map": "function (doc) {\n if(doc.type === \"asset\") {\n emit([doc.period, doc.correlationAssetId], 1);\n }\n}",
"reduce": "_count"
}
},
"language": "javascript"
}
a GET
request to query the view
https://$USER:$PASSWORD@$HOST/$DATABASE/_design/howdoi/_view/filter-by?inclusive_end=true&start_key=[%22201705%22]&end_key=[%22201705%22%2C{}]&reduce=true&group_level=2
should return the desired result if you specify start_key=["201705"]
and end_key=["201705",{}]
.
Example response if there are two documents within that period, both containing the same correlationAssetId
:
{
"rows": [
{
"key": [
"201705",
"aws-6082634880291"
],
"value": 2
}
]
}
The number of rows in the result set should identify the distinct number of correlationAssetId
s for the specified PERIOD.
Example result for two correlationAssetId
s:
{
"rows": [
{
"key": [
"201701",
"aws-6082634880291"
],
"value": 1
},
{
"key": [
"201701",
"aws-6082634880292"
],
"value": 1
}
]
}
P.S. Your example document didn't define the asset
property and your view definition would therefore not have returned the document. My response above assumes that that property is defined in the documents.