Honddoe
Honddoe

Reputation: 51

What is the purpose of _count in elastic search?

What is the purpose of _count in elastic search? I know that I can use endpoint _search to get the data in elastic search.

Thanks

Upvotes: 0

Views: 155

Answers (1)

Val
Val

Reputation: 217254

The purpose of the _count API is simply to get the number of matches for a given query.

It takes the same input as the _search API but without returning any hits, just a count of matches.

The Search API with size=0 would return this:

POST index/_search?size=0
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 10931164,
    "max_score" : 0.0,
    "hits" : [ ]
  }
}

While the Count API would return this:

POST index/_count
{
  "count" : 10931164,
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "skipped" : 0,
    "failed" : 0
  }
}

Upvotes: 1

Related Questions