<commit_before>[[search-count]]
== Count API

The count API allows to easily execute a query and get the number of
matches for that query. It can be executed across one or more indices
and across one or more types. The query can either be provided using a
simple query string as a parameter, or using the
<<query-dsl,Query DSL>> defined within the request
body. Here is an example:

[source,js]
--------------------------------------------------
$ curl -XGET 'http://localhost:9200/twitter/tweet/_count?q=user:kimchy'

$ curl -XGET 'http://localhost:9200/twitter/tweet/_count' -d '
{
    "term" : { "user" : "kimchy" }
}'
--------------------------------------------------

NOTE: The query being sent in the body must be nested in a `query` key, same as
the <<search-search,search api>> works added[1.0.0.RC1,The query was previously the top-level object].

Both examples above do the same thing, which is count the number of
tweets from the twitter index for a certain user. The result is:

[source,js]
--------------------------------------------------
{
    "count" : 1,
    "_shards" : {
        "total" : 5,
        "successful" : 5,<commit_msg>[DOCS] fixed count docs, it now requires a top-level query object, same as other apis<commit_after>[[search-count]]
== Count API

The count API allows to easily execute a query and get the number of
matches for that query. It can be executed across one or more indices
and across one or more types. The query can either be provided using a
simple query string as a parameter, or using the
<<query-dsl,Query DSL>> defined within the request
body. Here is an example:

[source,js]
--------------------------------------------------
$ curl -XGET 'http://localhost:9200/twitter/tweet/_count?q=user:kimchy'

$ curl -XGET 'http://localhost:9200/twitter/tweet/_count' -d '
{
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}'
--------------------------------------------------

NOTE: The query being sent in the body must be nested in a `query` key, same as
the <<search-search,search api>> works added[1.0.0.RC1,The query was previously the top-level object].

Both examples above do the same thing, which is count the number of
tweets from the twitter index for a certain user. The result is:

[source,js]
--------------------------------------------------
{
    "count" : 1,
    "_shards" : {
        "total" : 5,
        "successful" : 5,
{'fraction_non_alphanumeric': 0.21684737281067556, 'fraction_numerical': 0.012510425354462052, 'mean_word_length': 2.1649076517150396, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1867492', 'n_tokens_mistral': 684, 'n_tokens_neox': 657, 'n_words': 286}