countedit

client.count([params, [callback]])

Get the number of documents for the cluster, index, type, or a query.

Check the API Conventions and the elasticsearch docs for more information pertaining to this method.

Get the number of all documents in the cluster.

const { count } = await client.count();

Get the number of documents in an index.

const { count } = await client.count({
  index: 'index_name'
});

Get the number of documents matching a query.

const { count } = await client.count({
  index: 'index_name',
  body: {
    query: {
      filtered: {
        filter: {
          terms: {
            foo: ['bar']
          }
        }
      }
    }
  }
});

Params

ignoreUnavailable

Boolean — Whether specified concrete indices should be ignored when unavailable (missing or closed)

allowNoIndices

Boolean — Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes _all string or when no indices have been specified)

[expandWildcards=open]

String — Whether to expand wildcard expression to concrete indices that are open, closed or both.

Options
  • "open"
  • "closed"
  • "none"
  • "all"

minScore

Number — Include only documents with a specific _score value in the result

preference

String — Specify the node or shard the operation should be performed on (default: random)

routing

String, String[], Boolean — A comma-separated list of specific routing values

q

String — Query in the Lucene query string syntax

analyzer

String — The analyzer to use for the query string

analyzeWildcard

Boolean — Specify whether wildcard and prefix queries should be analyzed (default: false)

[defaultOperator=OR]

String — The default operator for query string query (AND or OR)

Options
  • "AND"
  • "OR"

df

String — The field to use as default where no field prefix is given in the query string

lenient

Boolean — Specify whether format-based query failures (such as providing text to a numeric field) should be ignored

terminateAfter

Number — The maximum count for each shard, upon reaching which the query execution will terminate early

index

String, String[], Boolean — A comma-separated list of indices to restrict the results

type

String, String[], Boolean — A comma-separated list of types to restrict the results

body

Object, JSON — An optional request body, as either JSON or a JSON serializable object. See the elasticsearch docs for details about what can be specified here.

back to top