This should work to count exact distinct values:
curl -X POST "localhost:9200/invoices/_search?size=0&pretty" -H 'Content-Type: application/json' -d '{
"aggs" : {
"types_count" : {
"value_count" : { "field" : "inv_number" }
},
"group_by_status": {
"terms": {
"field": "inv_number"
}
}
}
}'