IMPORTANT: elasticsearch.js has been replaced by the new Elasticsearch JavaScript client. We strongly advise you to migrate to the new client. To learn more, see the migration guide.
count
editcount
editclient.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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|