Best practice for getting the total count of a type?


(Joel Abrahamsson) #1

I'm trying to get the total count for all documents of a specific
type. My first idea was to just use the _count API without specifying
a query:

http://localhost.:9200/myindex/BlogPost/_count

But that fails ({"error":"No query to execute, not in body, and not
bounded to 'q' parameter"}).

What's the best way to get the count? Doing a query using the _count
API?
http://localhost.:9200/myindex/BlogPost/_count?q=*

Or using the _search API with no query specifying the search type?
http://localhost.:9200/myindex/BlogPost/_search?search_type=count

Thanks in advance!


(Clinton Gormley) #2

Hiya

Or using the _search API with no query specifying the search type?
http://localhost:9200/myindex/BlogPost/_search?search_type=count

This is just fine, otherwise:

curl http://localhost:9200/myindex/BlogPost/_count -d '{match_all:{}}'

clint


(system) #3